How to save pictures individually from sequence of pictures in its variables.

1 Ansicht (letzte 30 Tage)
Hi every one,
I am quite new to matlab. I have a project that I need to import sequence of TIFF images and then remove background of it and then make Power Spectral density (PSD) plots. So far I found a code to import the data but I steel need to know how I can save every picture in an individual variable in the loop so I can recall them later. this is my code.
Thank you for your help in advance.
clc
clearvars
myFolder='C:\Users\poori';% folder path
filePattern = fullfile(myFolder, '*.tiff');
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray(:,:,1:3)); % Display image.
drawnow; % Force display to update immediately.
end

Akzeptierte Antwort

Eric Delgado
Eric Delgado am 29 Sep. 2022
Hey @Pooria Samandi, just create a cell array "imageArray"...
myFolder ='C:\Users\poori';
filePattern = fullfile(myFolder, '*.tiff');
theFiles = dir(filePattern);
imageArray = {};
for ii = 1:numel(theFiles)
fullFileName = fullfile(theFiles(ii).folder, theFiles(ii).name);
fprintf('Now reading %s\n', fullFileName);
imageArray{ii} = imread(fullFileName);
imshow(imageArray{ii}(:,:,1:3));
drawnow
end
  3 Kommentare
Eric Delgado
Eric Delgado am 29 Sep. 2022
Just call imageArray{1} for the first one, imageArray{2} for the second and so on...
imageArray{1} is a handle for the first image of your folder. If you are using just script, then this variable will be in the base workspace of Matlab, so just call it. But if you are using functions, then you have to pass imageArray to the function (or declare imageArray as a global variable, which could be not a good idea).
BW = imbinarize(imageArray{1});
figure
imshowpair(imageArray{1}, BW, 'montage')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by