How to save pictures individually from sequence of pictures in its variables.
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pooria Samandi
el 29 de Sept. de 2022
Comentada: Pooria Samandi
el 29 de Sept. de 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 comentarios
Respuesta aceptada
Eric Delgado
el 29 de Sept. de 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 comentarios
Eric Delgado
el 29 de Sept. de 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')
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!