import multiple .tiff images into a structure, from a user inputed directory in matlab

You can use the dir function in MATLAB to get a list of all the .tiff files in the user-input directory. Then you can loop through this list and load each image using the imread function. You can store each image in a structure using the filename as the field name.

Here's an example code:

main.m
% Get user input directory
input_dir = uigetdir();

% Get list of all .tiff files
tiff_files = dir(fullfile(input_dir, '*.tiff'));

% Loop through each file and load into a structure
for i = 1:length(tiff_files)
    % Load image
    filename = fullfile(tiff_files(i).folder, tiff_files(i).name);
    img = imread(filename);
    
    % Add image to structure
    images.(tiff_files(i).name) = img;
end
401 chars
16 lines

This code will create a structure called images where each field is a .tiff filename and the value is the corresponding image data. You can access the individual images using dot notation, e.g. images.image1.tiff.

gistlibby LogSnag