How to open tiff stack images in for loop

1 回表示 (過去 30 日間)
Ratsimandresy Dina
Ratsimandresy Dina 2017 年 10 月 19 日
回答済み: Jan 2017 年 10 月 19 日
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.

回答 (1 件)

Jan
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));

カテゴリ

Help Center および File ExchangeImage Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by