2
I’m having trouble with a loop loop 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 printing the values within the loop it works, but immediately after the loop the three arrays are zeroed. Can someone 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
The code is just that?
– Woss
This piece of code is part of a larger code.. but the part that does what I mentioned "a loop that counts the white pixels of a piece of an image and stores the x and y position of the piece and the total white pixels", is all there.
– Taís Siqueira
strange, it doesn’t make sense that the data is zeroed when leaving the loop, is sure that there is no more code ?
– ederwander
exactly @ederwander. I don’t understand why this happens. As I said before, the part that counts the white pixels and stores the positions x and y and the total, is this.
– Taís Siqueira