Controlling Color and Light in Matlab: Bijan Mobasseri
Controlling Color and Light in Matlab: Bijan Mobasseri
Bijan Mobasseri
Department Of Electrical and Computer Engineering Villanova University
1 / 18
Objectives
2 / 18
Color spaces-RGB
Any arbitrary color can be represented by a combination of primary colors.
RGB space is an example of additive colors. This is how colors are displayed on monitors and Tvs. In the RGB cube, each axis represents a primary color. Any point in that space is a unique color.
4 / 18
Cyan, Magenta, Yellow and Black, is a subtractive color model used in printing. You see the reected color because the ink reduces the light that would otherwise be reected.
5 / 18
Hue, saturation and Value is cylindrical coordinate system. The angle corresponds to hue, the distance from the axis is saturation and the distance along the axis is value(brightness)
6 / 18
For images, color is controlled by either RGB values or a colormap. An RGB color image in Matlab has three planes of data, representing red, green and blue. RGB values may be in thee {0,1} range or {0,255}.
7 / 18
Indexed images
An indexed image has only one plane. Pixel color is determined by the colormap that must accompany the image.
8 / 18
Anatomy of a colormap
A colormap is an N 3 matrix where columns represent red, green and blue values and N is the number of colors in the colormap. For example, to read the color of the pixel with value 18, go to row 8 of the colormap and read the colors (0.16, 0.35, 0.06).
9 / 18
Example colormap
Clown is an example of an indexed image. When loaded, it comes with a matrix of data X and a colormap. The colormap must be used when displaying the image imshow(X,map) There are 81 rows in the colormap, representing 81 colors.
10 / 18
Interpreting colormaps
The pixel at (123,80) has an index of 9. To know what color it has, go to row 9 of the colormap and read the RGB values (0.289,0.125,0)
11 / 18
Matlab-dened colormaps
There are a number of native colormaps in Matlab shown below. They can be invoked using colormap(hsv) or any other colormap.
12 / 18
It is possible to convert RGB images to indexed images and vice versa. However, in the process you may lose color delity. Top:16 colors, bottom: thousands. m=imread(annehathaway.jpg); [X,map] = rgb2ind(m,16); imshow(X,map)
13 / 18
14 / 18
Color may represent the z-value of a surface(left), but it could also represent other properties, such as gradient(right)
surf(x,y,Z)
surf(x,y,z,gradient(Z))
15 / 18
Checkerboard plots
You can turn numerical data into a visual representation by using pcolor.
16 / 18
An appealing rendition of 3D surfaces can be obtained by looking at their surface contours projected on the X-Y plane. A contour describes the location of constant Z-value. [x,y,z]=peaks; contourf(x,y,z) colormap(jet)
17 / 18
It is particularly informative to superimpose the 3D surface and its contours. It takes a little trickery
18 / 18