Cropping a tif stack
19 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!