Exceed array bound at position 2
Show older comments
Hi guys, I am trying to calculate the matrix moments for a binary image, however I encountered the following error:
>> run_A_2
Index in position 2 exceeds array bounds. Index must not exceed 438.
Error in features_2 (line 35)
m01 = m01 + j * Iin(i,j) / 255;
Error in run_A_2 (line 6)
[P, A, C, xbar, ybar, phione] = features_2(I1);
Here is my code:
function [P, A, C, xbar, ybar, phione] = features_2(Iin)
%perimeter
P = sum(sum(bwperim(Iin)==1)); %bwperim returns the perimeter
%by calculating the distance between
%each adjoining pair of pixels around
%the border of the binary image.
%area
A = sum(sum(Iin == 255)); %summing the number of pixel that are white
%compactness
C = P^2/(4 * pi * A);
%centroid
[rows cols] = size(Iin);
m00 = A;
m10 = 0;
m01 = 0;
%calculating m10
for i = 1:rows
for j = 1:cols
m10 = m10 + j * Iin(i,j) / 255;
end
end
%calculating m01
for i = 1:cols
for j = 1:rows
m01 = m01 + j * Iin(i,j) / 255;
end
end
xbar = m10 / m00; %m10/m00
ybar = m01 / m00; %m01/m00
May I know what is the issue?
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Image Transforms 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!