What's the difference between above two representation of white color? I'm a bit confused, and how they are used?
The two equivalent representations are
uint8([255 255 255])
and
double([1 1 1])
These are just the integer and floating-point representations. Note that uint8([1 1 1])
will be (almost) black and that double([255 255 255])
will usually cause an error.
Note that the integer version is only generally permitted by the image-handling functions, like imread
, imwrite
and image
. Everything else will expect the floating-point representation.
These two representations of white color refer to the RGB color model in which Red, Green and Blue lights are added together (additive color model) to produce the desired color.
Each one of the three basic light is usually coded with an 8 bits integer which therefore ranges from 0 to 255 (0 meaning total absence of this light).
In Matlab, these codes are often normalized by 255 and are floats between 0 and 1. Note that this is not the case when you open an image using imread
for exemple, so you have to be careful and refer to the relevant parts of the documentation.
Example: if you want to specify a particular color with an RGB code for a plot you can use plot(data,'color',[0 1 1]);
. This plot your data with the color cyan (green+blue).
See Matlab color specification for other ways of specifying colors in Matlab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With