Index in position 1 is invalid. Array indices must be positive integers or logical values.
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I am trying to get edge detected images from the code below but it keeps telling the same error which is :
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in
elseif ( IF(i+1,j)<0 || IF(i-1,j)<0 || IF(i,j+1)<0 || IF(i,j-1)<0 || IF(i-1, j-1)<0 || IF(i-1, j+1)<0 || IF(i+1,
j+1)<0 || IF(i+1, j-1)<0)
Please could anyone help me resolving the problem, thank you!
close all;
clc;
%Input image
inim = imread ('ruins.jpg');
inimg = rgb2gray(inim);
%Value for Thresholding
T_Low = 0.075;
T_High = 0.175;
k = 2;
delta_t = 0.1;
col=size(inimg,1);
row=size(inimg,2);
cC = ((abs(inimg)).^2)./(1 + ((abs(inimg).^2).*delta_t)).^k;
F = fft(inimg);
J = cC .* F;
IF1 = ifft(J);
IF = real(IF1);
%Hysteresis Thresholding
T_Low = T_Low * max(max(IF));
T_High = T_High * max(max(IF));
T_res = zeros (pan, leb);
for i = 1 : col
for j = 1 : row
if (IF(i, j) < T_Low)
T_res(i, j) = 0;
elseif(IF(i, j) > T_High)
T_res(i, j) = 1;
%look for the negative in 8-connected components
elseif ( IF(i+1,j)<0 || IF(i-1,j)<0 || IF(i,j+1)<0 || IF(i,j-1)<0 || IF(i-1, j-1)<0 || IF(i-1, j+1)<0 || IF(i+1, j+1)<0 || IF(i+1, j-1)<0)
T_res(i,j) = 1;
end
end
end
0 个评论
回答(1 个)
KALYAN ACHARJYA
2019-5-19
编辑:KALYAN ACHARJYA
2019-5-19
( IF(i+1,j)<0 || IF(i-1,j)<0 || IF(i,j+1)<0 || IF(i,j-1)<0 || IF(i-1, j-1)<0 || IF(i-1, j+1)<0 ||
%......^.............^................^............^...so on
When i=1.............^^ becomes zero that menas IF(i-1,j)>>IF(0,j)
When j=1............................................^^ >>IF(i,0)
These array indeces must be non zero positive integer.
IF (0,2)>> not allowed
IF(-2,4) not allowed
IF(1,1) allowed
IF(2,0) not allowed
IF(5,5) is allowed
Also ensure during array indexing, length of array doesnot exceed, otherwise it will reflects another type of array "array exceeds ....."
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!