Subscript indices must either be real positive integers or logicals.

2 views (last 30 days)
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.

Accepted Answer

Geoff Hayes
Geoff Hayes on 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.
  1 Comment
Jhilam Mukherjee
Jhilam Mukherjee on 12 Oct 2014
Thanks Hayes. My problem is solved. But I have face another problem, I have taken 5 point using getpts, I have execute regiongrow algorithm 5 times, as a result I obtain 5 output image. But I want to get a single output image containing result of each five output image. but I can't get my desire output. close all; I=imread('CT6.jpg'); I=im2double(I); I=rgb2gray(I); figure,imshow(I); hold on; [y x]=getpts; n=length(x); hold off; %t=multithresh(I); %t=adaptivethreshold(I,11,0.03,0) J=zeros(10,10); for i=1:n-1 x(i)=round(x(i)); y(i)=round(y(i)); %N=J; J = regiongrowing(I,x(i),y(i),0.1); %J=(J,J); K=imadd(J,J) % subplot(1,2,1), imshow(J) % subplot(1,2,2), imshow(N) figure,imshow(J);
end figure,imshow(J);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!