I'm having trouble with a loopback that counts the white pixels of a piece of an image and stores the position x and y of the piece and the total of white pixels. When I print the values inside the loop it works, but immediately after the loop the three arrays are zeroed. Can anyone help me?
Code:
y = zeros(altura*largura);
x = zeros(altura*largura);
v = zeros(altura*largura);
for j=0:altura-1
for k=0:largura-1
pedaco = f8(j*40+1 : j*40+40, k*40+1 : k*40+40); %binary piece
pedac = im2uint8(pedaco);
totalBrancos = sum(sum(pedac)); %sum white pixels
pos = altura*j+k+1;
y(pos) = j;
x(pos) = k;
v(pos) = totalBrancos;
disp(y(pos)); %works
disp(x(pos)); %works
disp(v(pos)); %works
end
end
disp(y); %all zeros
disp(x); %all zeros
disp(v); %all zeros