Reputation: 1
I'm trying to calculate the pixels within a range. I calculated the range, but I can't count the pixels containing 0.
My code:
first_value_of_i = zeros(M,1);
first_value_of_j = zeros(N,1);
second_value_of_i = zeros(M,1);
second_value_of_j =zeros(N,1);
for i = 2:M-1
for j = 2:N-1
Pix = [image(i,j) image(i-1,j) image(i-1,j+1) image(i,j+1) image(i+1,j+1) image(i+1,j) image(i+1,j-1) image(i,j-1) image(i-1,j-1) image(i-1,j)];
if((Pix(1)==0) && ( (Pix(2)*Pix(3)*Pix(4)*Pix(5)*Pix(6)==0) || (Pix(2)*Pix(6)*Pix(7)*Pix(8)*Pix(9)==0)))
if (((Pix(2)+Pix(6)+Pix(7)+Pix(8)+Pix(9))>=5) || ((Pix(2)+Pix(3)+Pix(4)+Pix(5)+Pix(6))>=5))
first_value_of_i(i,1) = i;
first_value_of_j(j,1) = j;
end
if (((Pix(2)+Pix(3)+Pix(4)+Pix(8)+Pix(9))>=5) || ((Pix(4)+Pix(5)+Pix(6)+Pix(7)+Pix(8))>=5))
second_value_of_i(i,1) = i;
second_value_of_j(j,1) = j;
end
end % if
end %for
end %for
rest_stroke = zeros(M,2);
for p = first_value_of_i : second_value_of_i
count_rest=0;
for q = first_value_of_j:second_value_of_j
if((image(p,q)==0))
count_rest=count_rest+1;
end
end
rest_stroke(i,1)=i;
rest_stroke(i,2)=count_rest;
end
But the output shows:
Subscript indices must either be real positive integers or logicals.
Error in trying (line 173)
if((image(p,q)==0))
According to my calculation it should be ok, but evidently, it is not. Can anyone help me out?
Upvotes: 0
Views: 42
Reputation: 2993
for i=2:M-1
for j = 2:N-1
i
begins at 2. first_value_of_i(1,1)
is initialized as 0 and not changed.
Upvotes: 2