Cropping a tif stack

조회 수: 18 (최근 30일)
mtmtmt
mtmtmt 2017년 1월 23일
댓글: Huan Zheng 2020년 9월 19일
Hey everyone,
I need to crop a stack of single tif-files. For example, I have a stack of 5000 512x512 tif images where I only need the regions from x=159 to 295 and y=279 to 389. Is there a way to do this fast in MATLAB? I have written the code below, using parfor, but it still takes a long time, and I have the impression that it could be done better...
Thanks!
im=imread('filename.tif');
filename='filename.tif';
info=imfinfo(filename);
num_images=numel(info);
parfor k = 1:num_images
A=imread(filename,k,'Info',info);
Acrop=imcrop(A,[5 10 50 75]);
imwrite(Acrop,'stack_crop.tif','writemode','append');
end
  댓글 수: 1
Huan Zheng
Huan Zheng 2020년 9월 19일
Hi, I met the same issue now, do you have any solution after 3 years?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 1월 23일
You can do slightly better by using array indexing instead of imcrop, since you already know the section you want to extract.
However, your output is not well defined. parfor does not execute the loop in-order, so the order of images is going to be random in 'writemode' 'append'
  댓글 수: 2
mtmtmt
mtmtmt 2017년 1월 23일
Thanks a lot for your answer!
It is interesting that the images seem to be in order in my case... Though it would not be a problem if they were random.
Apart from that - can I do more than just using array indexing?
Walter Roberson
Walter Roberson 2017년 1월 23일
Possibly switching to using the Tiff class might help. No promises.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by