0
votes

I have an image (5x5)pixels with 3 values which value 0, 128, and 255.

I want to check the pixels of the index (1,1) to (1,5).

If there is pixel value 0 (black), then the pixels of the index (1,1) to (1,5) is changed to 128 (gray), if none, then the pixels are changed to 255 (white).

I want to do these steps again, checking of the index (2,1) to (2,5), (3,1) to (3,5), through to the bottom.

from the above problems, I get a solution like this:

mask = repmat(any(I == 0,2),5,1);

I(mask) = 128;

I(~mask) = 255;

but if I want to check pixels vertically, from the index (1,1) to (5,1), then to the right, the index (1,2) to (5,2), until the end. what's the solution?

Thank You

Regards, Wahyu

1
I am not sure if I completely understand your question, but a straightforward way to find all zero pixels in the image would be `img = [0,5,3; 0,0,7; 0,3,0]; zeroPixels = logical(img == 0); You could easily do something like that to find the non-zero values.Herr von Wurst

1 Answers

1
votes

You could just transpose your matrix/image, use the solution you were given in your previous question and then transpose again to get back to the original matrix/image:

I = I';
%# Do solution you got last time here
%#{

%#}

I = I';