How to open tiff stack images in for loop

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.

Respuestas (1)

Jan
Jan el 19 de Oct. de 2017
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));

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Oct. de 2017

Respondida:

Jan
el 19 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by