import multiple .tiff images into a structure, with fields of filename and resolution(pixels), and a user inputed pixel size(um) field in matlab

To import multiple .tiff images into a structure with fields of filename and resolution (in pixels), and a user inputed pixel size (in micrometers) field in MATLAB, you can use the following code:

main.m
% User inputs
pixelSize = input('Enter the pixel size in micrometers: ');

% Get the list of .tiff images in the current directory
fileList = dir('*.tiff');

% Loop through each file and create a structure with filename and resolution
for i = 1:length(fileList)
    
    % Read the image file
    img = imread(fileList(i).name);
    
    % Get the image resolution
    imgSize = size(img);
    
    % Create a structure with the filename, resolution in pixels, and pixel size in micrometers
    imageStruct(i).filename = fileList(i).name;
    imageStruct(i).resolution = sprintf('%dx%d', imgSize(1), imgSize(2));
    imageStruct(i).pixelSize = pixelSize;
    
end

% Display the structure
disp(imageStruct);

709 chars
26 lines

In this code, the user is prompted to input the pixel size in micrometers. Then, the dir function is used to get a list of all the .tiff images in the current directory. A for loop is used to loop through each file in the list, and the imread function is used to read the image file. The size function is used to get the image resolution in pixels.

A structure is created for each image with fields for the filename, resolution in pixels, and pixel size in micrometers. These structures are stored in an array called imageStruct. Finally, the disp function is used to display the imageStruct.

gistlibby LogSnag