Problem in looping. contour command is not working on all the images, only the values from last image is printing. I want the C values from all the images

1 次查看(过去 30 天)
hi,
I am using the code below to read the images from the folder, and in work space I can see it is reading all the images but then I want to apply the contour command as shown below to all the images and extract C from all the images but the code is only extracting the information from the last image. Can you guys guide me what needs to be done in the code below.
Code:
srcFile=dir('D:\ImageAnalysis\NewAnalysis\Images\*.png')
for i=1:length(srcFile)
filename=strcat('D:\ImageAnalysis\NewAnalysis\Images\',srcFile(i).name);
I=imread(filename);
[C,h] = imcontour(I,2);
end

采纳的回答

Ameer Hamza
Ameer Hamza 2020-11-17
编辑:Ameer Hamza 2020-11-17
Because you are overwriting these variable in each iteration. Create a cell array
srcFile=dir('D:\ImageAnalysis\NewAnalysis\Images\*.png')
C = cell(1,numel(srcFile));
h = cell(1,numel(srcFile));
for i=1:length(srcFile)
filename=strcat('D:\ImageAnalysis\NewAnalysis\Images\',srcFile(i).name);
I=imread(filename);
[C{i},h{i}] = imcontour(I,2);
end
Read about cell arrays here: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html. You can access values in cell arrays using brace indexing
C{1}
C{2}
..
C{end}

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by