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 visualización (últimos 30 días)
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

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 17 de Nov. de 2020
Editada: Ameer Hamza el 17 de Nov. de 2020
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}

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image 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!

Translated by