import multiple .tiff images into a structure in matlab

main.m
% Define directory containing the TIFF images
directory = '/path/to/tiff/images/';

% Get list of TIFF files in the directory
filelist = dir(fullfile(directory,'*.tif'));

% Loop over each TIFF file and read it into a structure
for i = 1:length(filelist)
    % Read the TIFF file using imread
    img = imread(fullfile(directory,filelist(i).name));
    % Store the image data in a field of the structure
    images(i).data = img;
    % Store the file name in another field of the structure
    images(i).filename = filelist(i).name;
end
537 chars
16 lines

The above code imports all the TIFF images present in the specified directory into a structure called images. The image data is stored in a field called data, and the file name is stored in a field called filename. The resulting structure can be used to access the image data and the associated file names.

gistlibby LogSnag