read multiple high resolution Images
이전 댓글 표시
Hi,
I have a set of 400 images of 1024 x 1024 resolution. I want to open each of the 400 images and extract a perticular row of each image and form a new image out of this. So the resulting number of images will be 1024 each of size 400 x 1024. I need to save these 1024 images separately.
I am able to do this but it is taking more time. I am running a for loop to read/load images from directory one by one, shredding them into a variable of size 1024 x 400 x 1024 size variable. Then running another for loop to save these images.
My question: Is there any better/faster way of doing this (like cell arrays etc or otherwise). Currently it is taking about 80 sec. (intel i-3, win10, r17a).
댓글 수: 7
Geoff Hayes
2020년 4월 21일
Rajesh - have you presized your "destination" array (the 1024x400x1024)? Could you put the "file saving code" into the same loop where you read the files from (and perhaps avoid having the need for the destination array):
% get list of images
% loop over each image
for k = 1:numImages
% read image
% extract subset of data
% save smaller image to file
end
Image Analyst
2020년 4월 21일
Why do you have a 3-D variable? If you're extracting one row from 400 images, and stitching them together, won't the final image be just one image of 400x1024? How are you getting/wanting 1024 images?
Rajesh Acharya
2020년 4월 22일
Bjorn Gustavsson
2020년 4월 22일
As Geoff indicates this is a problem of memmory reallocation. If you can pre-allocate your sinogram variable:
sinogram = zeros([400 1024 1024]);
before the loop then matlab will not have to grow that variable every step in the loop. Also you should be able to skip the inner loop over rows and replace that with:
sinogram(file,:,:) = presino_image.';
Obviously if the first allocation fails you'll have to divide-to-conquer and save some fraction of the sinograms, then another fraction...
HTH
Rajesh Acharya
2020년 4월 22일
Bjorn Gustavsson
2020년 4월 22일
My bad missing that line.
sinogram becomes a rather large variable. I encountered similar slowing-downs when some 3-D arrays started to grow. This might be a memmory-issue.
If this becomes "punitively slow" you might have to resort to extracting sinograms from the first half then the second half of your files, and then concateneat the first-half and second-half sinogram-slices together file-by-file. This is an uggly-uggly thing to have to do, but might save you time.
HTH
Rajesh Acharya
2020년 4월 22일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!