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
0 个评论
采纳的回答
Eric Delgado
2022-9-29
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
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!