Subscript indices must either be real positive integers or logicals.

2 views (last 30 days)
I am implementing hough transform to detect the circle in edge image.
Here is my code:
-----------------------------------------------------------------
EI=imread('Auto3.jpg');
figure,imshow(EI);
EI=im2double(EI);
EIG=rgb2gray(EI);
[CEIG, thresh]=edge(EIG,'canny',[],.5);
[rows, columns]=size(CEIG);
R=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
H=zeros(rows,columns,length(R));
[yIndex, xIndex]=find(CEIG);
for count=1:length(xIndex)
for r=1:20
for yz=121:240
xz=xIndex(count)-sqrt(R(r)^2-(yIndex(count)-yz)^2);
xz=round(xz);
if xz >= 1 && xz <= rows
H(yz,xz,r) = H(yz,xz,r)+1;
end
end
end
end
-----------------------------------------------------------------
And the error is:
Subscript indices must either be real positive
integers or logicals.
Error in Test (line 23)
H(yz,xz,r) = H(yz,xz,r)+1;

Answers (2)

Walter Roberson
Walter Roberson on 31 Jan 2013
At the command line, command
clear all
dbstop if error
and then run the program. If/when it stops, examine the yz, xz, and r values.

Matt J
Matt J on 31 Jan 2013
You need to ensure in some way that
xz=xIndex(count)-sqrt(R(r)^2-(yIndex(count)-yz)^2);
doesn't generate complex values. Using ROUND will not fix that.

Community Treasure Hunt

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

Start Hunting!