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 日間)
古いコメントを表示
muhammad choudhry
2020 年 11 月 17 日
コメント済み: muhammad choudhry
2020 年 11 月 17 日
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 件のコメント
採用された回答
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 Center および File 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!