Index in position 1 is invalid. Array indices must be positive integers or logical values.
조회 수: 4 (최근 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에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!