Subscript indices must either be real positive integers or logicals.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jhilam Mukherjee
le 10 Oct 2014
Commenté : Jhilam Mukherjee
le 12 Oct 2014
I want to execute regiongrow to segment an image. Each image have more than one region to segment I have taken seed point using getpts for each region. I have execute the proram and face above error. My code is
I=imread('medtest.png');
I=im2double(I);
figure,imshow(I);
% [M N]=size(I)
% x=M+N/2;
% y=N-M/2;
hold on;
[x y]=getpts;
n=length(x)
hold off;
for i=1:n
a{i}=x;
b{i}=y;
J{i} = regiongrowing(I,a{i},b{i},0.2);
figure,
imshow(J{i});
end
How it can be overcome.
0 commentaires
Réponse acceptée
Geoff Hayes
le 11 Oct 2014
Jhilam - I can't run your code since I don't have the Image Processing Toolbox (needed for getpts), but the error message is telling you that indices that you are using for some array are neither positive integers nor logicals. So either the index or indices are zero, or they are rational (i.e. 1.2). Look at how x and y are determined
[x y]=getpts;
and the two variables represent a set of points in the current axes that you have selected. But what guarantee is it that they are integers? If you put a breakpoint at the line
n=length(x)
what do x and y look like - are they integers or rational numbers? I suspect they might be the latter, especially if you look at the attached file regiongrowing.m. If you don't supply the x and y, then the code calls the same getpts function to grab these values. But look at what it does with them
if(exist('y','var')==0)
figure
imshow(I,[]);
[y,x]=getpts;
y=round(y(1));
x=round(x(1));
end
It calls round on each of the first two elements in x and y to ensure that they are integers (though I suppose this could round some small value down to zero if points like 0.3 are allowed).
So I think the authors of this code realized that those values returned from getpts could be rational numbers and so have tried to account for this using round. Your code should probably do the same thing
[x y]=getpts;
n=length(x);
% round the points
x=round(x);
y=round(y);
% etc.
You may also want to do the following to ensure no x and y values fall outside the size of your image
% assume grayscale image only
[m,n] = size(I);
x(x<1) = 1;
y(y<1) = 1;
x(x>n) = n;
y(y>m) = m;
Note the assumption which I think is valid in your case.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!