How to open tiff stack images in for loop
4 次查看(过去 30 天)
显示 更早的评论
I have a folder F. Under that folder, I have 20 multipage stack .tiff image.
Each image A in the folder F is a stack of 50images and I need to average those 50images to get only one image B and do the average over the rows of image B then save the mean in an excel file. Here is my code
myexcel = 'F\interference2.xlsx';
out = zeros(1280,20);
for k = 1:20
fname = ['F\image',num2str(k),'.tiff'];
info = imfinfo(fname);
num_images = numel(info); %50images
Z = zeros(1024,1280);
for jj = 1:num_images
Z = Z + double(imread(fname, jj, 'Info', info)); %sum of the 50images
end
avrg = mean(Z/50); %average
out(:,k) = avrg; % store a column in a matrix out
end
xlswrite(myexcel ,out)
It always gives an error: Error using imfinfo (line 100) Unable to open file "F\image1.tiff" for reading.
Error in interf (line 13) info = imfinfo(fname);
Thanks for your help.
0 个评论
回答(1 个)
Jan
2017-10-19
The error message means, that the file cannot be opened. Most likely it does not even exist, because the path is wrong. Use an absolute path instead:
folder = 'C:\Temp\Your\Folder';
...
fname = fullfile(folder, sprintf('image%d.tiff', k));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!