0% found this document useful (0 votes)
43 views18 pages

Controlling Color and Light in Matlab: Bijan Mobasseri

This document discusses controlling color and light in Matlab. It begins by stating the objectives which are to understand color spaces, how to communicate color information to Matlab, how to control color assignment in Matlab, and the notion of colormaps. It then discusses several color spaces including RGB, CMYK, and HSV. It explains how color is represented in Matlab for RGB images using RGB values or colormaps, and for indexed images using a colormap. It provides an example of interpreting pixel color values from a colormap. Finally, it demonstrates several ways to visualize and represent color data in Matlab plots and images.

Uploaded by

sachikoyamada
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views18 pages

Controlling Color and Light in Matlab: Bijan Mobasseri

This document discusses controlling color and light in Matlab. It begins by stating the objectives which are to understand color spaces, how to communicate color information to Matlab, how to control color assignment in Matlab, and the notion of colormaps. It then discusses several color spaces including RGB, CMYK, and HSV. It explains how color is represented in Matlab for RGB images using RGB values or colormaps, and for indexed images using a colormap. It provides an example of interpreting pixel color values from a colormap. Finally, it demonstrates several ways to visualize and represent color data in Matlab plots and images.

Uploaded by

sachikoyamada
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Controlling Color and Light in Matlab

Bijan Mobasseri
Department Of Electrical and Computer Engineering Villanova University

November 12, 2012

1 / 18

Objectives

By the end of this lecture, you should know the following,


Understanding of color spaces. How to communicate color information to Matlab. How to control color assignment in Matlab. Notion of colormap. Writing and modifying your own colormap.

2 / 18

Need for color assignment


Notice color is used to convey two different types of information.

Color proportional to Z-value.

Color proportional to curvature.


3 / 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

CMYK color space

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

HSV color space

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

Color in Matlab-RGB images

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

Converting RGB images to indexed images

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

Plotting an image as a surface


An image is in fact a matrix of data and may be treated as such using surf(X).

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

Filled contours via contourf

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

Combining contours and 3D surfaces

It is particularly informative to superimpose the 3D surface and its contours. It takes a little trickery

18 / 18

You might also like