How to open tiff stack images in for loop

조회 수: 4 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by