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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
muhammad choudhry
am 17 Nov. 2020
Kommentiert: muhammad choudhry
am 17 Nov. 2020
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
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 17 Nov. 2020
Bearbeitet: Ameer Hamza
am 17 Nov. 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}
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!