How to save pictures individually from sequence of pictures in its variables.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pooria Samandi
le 29 Sep 2022
Commenté : Pooria Samandi
le 29 Sep 2022
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
0 commentaires
Réponse acceptée
Eric Delgado
le 29 Sep 2022
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 commentaires
Eric Delgado
le 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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!