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

1 次查看(过去 30 天)
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

采纳的回答

Eric Delgado
Eric Delgado 2022-9-29
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 个评论
Eric Delgado
Eric Delgado 2022-9-29
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')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by