From: Walter Roberson on
Faiz Ali wrote:
> Hi,
> I am doing project "AUTOMATIC NUMBER PLATE RECOGNITION". i want to read
> each pixel of an image and get its color. if the obtained color is not
> white, den it should change to black. Can anyone help me with codes of
> this??

Is this image an indexed image (a 2D matrix) or a true-color image (a 3D
matrix with the third dimension being the color) ? And what data type is it,
double or single or uint8 or uint16 ?


If it is a 3D matrix of double, and is named M, then:

M(repmat(prod(M,3) < 1,1,1,3)) = 0;


Note that this considers a pixel to be "white" only if its R, G, and B are all
the maximum possible value, 1.0 . If even just one of the pixel values is a
hair less than pure 1.0 then it will deem the pixel to be "not white" and will
change it to black.

This definition of what "white" is, is at odds with the definition of white as
containing an equal mix of amplitudes and frequencies, but perhaps varying in
brightness -- so, for example, [0.8, 0.8., 0.8] would sometimes be considered
"white", just not as bright as [1, 1, 1]. If that is the definition of white
that you wish to use, then keep in mind that under that definition, [0, 0, 0]
(which is conventionally called black) could also be considered "white that
happens to have 0 brightness", and that [1,1,1] would also be considered "a
very dim white" and so on.

I won't bother to present code for these other possibilities, because there
are too many different meanings of what "white" means. Is [1, 1, 0.999999]
white? Would you be able to tell the difference between that and [1, 1, 1] ?
(The answer to that question is, by the way "not with the human eye, not even
under the best of conditions!")