??? Subscript indices must either be real positive integers or logicals.
1 次查看(过去 30 天)
显示 更早的评论
Hello, i need help. I will be grateful for any advice.
I have to clustering grayscale image.
I enclose my code The main function is kmnsImage.
error in :
??? Subscript indices must either be real positive integers
or logicals.
Error in ==> KMNSimage at 542
cluster(Z{ii}) = ii;
I must to clustering grayscale image,so that the pixels in a similar intensities were in one cluster.
Please help me.
Thank you for your help
3 个评论
Geoff Hayes
2014-4-27
编辑:Geoff Hayes
2014-4-27
Hi Tomas,
Try putting in some breakpoints in and around line 542 and check to see what your value of ii is being set to. Given the error, it sounds like your ii is being set to zero or some rational (or fraction of a) number.
If there are several iterations of the loop (over ii) then it may take some time to step through all iterations until the failure occurs. Sometimes, what I do, is to wrap the trouble spot in a try catch block and then just put the breakpoint in the catch. So when the error occurs, the code pauses in the catch:
try
cluster(X{ii}) = ii;
catch
fprintf('error!');
end
The breakpoint will be on the line of the fprintf, and you can debug here to see what the value of ii is.
Geoff
回答(1 个)
Image Analyst
2014-4-27
Then try this:
try
whos X
whos ii
fprintf('X{%d} = %d\n', ii, X{ii});
index = X{ii}
cluster(index) = ii;
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
15 个评论
Image Analyst
2014-4-28
编辑:Image Analyst
2014-4-28
So like I said, you want to label the image. All pixels in spot #1 should be labeled 1, and all pixels in spot #2 should be labeled #2, and so on. This is precisely what bwlabel does in one line, and what the kmeans code that I gave over in your duplicate question does, reproduced below here:
classifiedImage = zeros(size(I), 'int32');
for p = 1 : length(IDX)
row = P(p, 1);
column = P(p, 2);
% Set this pixel of the classified image
% to the class it identified for that pixel.
classifiedImage(row, column) = IDX(p);
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!