Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab RGB color representation ([255 255 255] and [1 1 1])

What's the difference between above two representation of white color? I'm a bit confused, and how they are used?

like image 542
Elsie Avatar asked Jan 18 '23 14:01

Elsie


2 Answers

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.

like image 193
Nzbuu Avatar answered Jan 31 '23 06:01

Nzbuu


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.

like image 42
Aabaz Avatar answered Jan 31 '23 08:01

Aabaz