Hi, I'm new with Matlab and while doing my coding for canny edge detection, I got this error from the line that I bold.Can someone help me with this error? Thank you in advanced. "Subscript indices must either be real positive integers or logicals."

4 views (last 30 days)
%Hysteresis Thresholding
T_Low = T_Low * max(max(BW));
T_High = T_High * max(max(BW));
T_res = zeros (pan, leb);
for i = 1 : pan
for j = 1 : leb
if (BW(i, j) < T_Low)
T_res(i, j) = 0;
elseif (BW(i, j) > T_High)
T_res(i, j) = 1;
% Using 8-connected components
elseif ( BW(i+1,j)>T_High || BW(i-1,j)>T_High || BW(i,j+1)>T_High || BW(i,j-1)>T_High || BW(i-1, j-1)>T_High || BW(i-1, j+1)>T_High || BW(i+1, j+1)>T_High || BW(i+1, j-1)>T_High) %THIS LINE
T_res(i,j) = 1;
end
end
end

Answers (2)

Ameer Hamza
Ameer Hamza on 19 May 2018
In your code, you are trying to access values like
BW(i-1,j)
so when i=1 this becomes B(0,j). In MATLAB index zero is not allowed. Therefore you are getting the error the subscript must be a real positive integer.

Image Analyst
Image Analyst on 19 May 2018
Edited: Image Analyst on 19 May 2018
What is your definition of hysteresis thresholding? It looks like you're simply doing thresholding and dilation:
binaryImage = T_res > T_high;
binaryImage = imdilate(binaryImage, true(3));
It seems that is essentially what your loop boils down to.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!