??? Attempted to access cmtx(1.00024,1); index must be a positive integer or logical.
1 view (last 30 days)
Show older comments
hello sir, I am working with a image . and i am applying entropic thresholding on the image ,and i get the error. how to solve this error
"??? Attempted to access cmtx(1.00024,1); index must be a positive integer or logical."
Error in ==> file1>GABOR_Callback at 809
cmtx(fix(rt(m,n))+1,fix(rt(m,n+1))+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1
here rt is my image
and my thresholding code is
[M,N] =size(rt);
cmtx = zeros(256,256);
for m = 1:M-1
for n = 1:N-1
cmtx(rt(m,n)+1,rt(m,n+1)+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1;
end
end
scmtx = sum(cmtx(:)); prob = cmtx/scmtx;
emax = -100; for i=1:255
probA = 0;
probC = 0;
subProbA = prob(1:i,1:i);
probA = sum(subProbA(:));
HA(i) = -0.5*(probA*log2(probA+0.0000001));
subProbC = prob(i+1:256,i+1:256);
probC = sum(subProbC(:));
HC(i) = -0.5*(probC*log2(probC+0.0000001));
e1(i) = HA(i) + HC(i);
if e1(i) >= emax
emax = e1(i);
tt1 = i;
end
end
end
0 Comments
Accepted Answer
David Sanchez
on 22 Nov 2013
your sentece:
cmtx(fix(rt(m,n))+1,fix(rt(m,n+1))+1) = cmtx(rt(m,n)+1,rt(m+1,n+1)+1) + 1
returns a value for
rt(m,n)+1 = 1.00024
you can only access integer values when dealing with matrices. Try to round the values of both rt(m,n)+1 and rt(m+1,n+1)+1 or modify your rt function in order to avoid decimals:
round(rt(m,n)+1) = 1
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!