Professional Documents
Culture Documents
Assignment 2
Exercise 1 Color Image Creation
To begin you are requested to create three 3 X 3 ”images” having only 0 and 1 as elements. These
images will be the red, green, and blue component images of a 3 × 3 color image that you will display.
The color image should look like this:
a. After you have created the r, g and b images, use the Matlab statements
>> rgb_image = cat(3,r,g,b);
>> imshow(rgb_image);
to display the image. Look at the image carefully to confirm that you have placed the saturated
primary colors RGB and CMY in the correct places. Print the values of the three images by using
the Matlab command
>> [r,g,b]
The resulting image plot is rather small (3 x 3 pixels). Use the magnification feature of the
imshow command to scale the color image to a larger size for viewing.
b. To convert to an indexed image representation, open a new image display window, and
display that representation. Compare the two displays. They should be the same. Use the
Matlab statements
>> [X,map]=rgb2ind(rgb_image, N); % try different values for N
>> figure(2);
>> imshow(X,map);
c. Now use the Matlab statement
>> map
to print the color map that was generated by the function rgb2ind. Using this printout and the
values of the indexed image X verify that you understand how the colors are represented in the
indexed image. Include an explanation in your report
d. Finally, scale each of the images by a constant that is less than one and display it; e.g., scaling by
0.8 is implemented as:
>> c=0.8;
>> rgb_scaled=cat(3,r*c,g*c,b*c);
>> imshow(rgb_scaled)
Use values of c = 0.8, 0.6, 0.4, 0.2 to observe the effect. Report: What happens to the colors as c
is varied over the range of values?
Load and display the color image corn.tif using the statements
>> [corn,map] = imread(“corn.tif”);
>> imshow(corn,map);
Examine the size of corn by typing whos to find out the size of the image that you have read in.
a. Use a small part of the variable map (reduced_map=map(1:N,:) to evaluate the effect of
reduce the map levels. Report: For what value of N do you begin to see some distortion?
b. Use ind2rgb function to convert your indexed figure to a rgb image. Show your results and
compare the size of variables.
c. Use rgb2gray function to convert the rgb image to a gray level image, Report the results that
you obtain
d. Use the imcomplement function to obtain the complement of your rgb and gray images.
Discuss the results. Does the displayed image look like a photographic negative?
As discussed in class, NTSC television uses a YIQ representation instead of RGB so that black and
white television sets can display a color television signal. The conversion operations are
a. Convert the color image ’corn.tif’ from RGB to YIQ format using the relevant Matlab command
yib_image=rgb2ntsc(rgb_image). Using the mutliplot capability plot the R, G, B and RGB
composite components in a 2 x 2 image plot format.
b. Plot the Y, I, Q components of the image (along with the composite RGB image) in another 2 x 2
image plot.
c. Recalling that R, G, and B are intensity images such that 0 ≤ R ≤ 1, 0 ≤ G ≤ 1, and 0 ≤ B ≤ 1,
determine the ranges of the YIQ variables. These ranges are important, since only if Y , I, and Q
satisfy them can we guarantee that the inverse transformation will give values of R, G, and B in
the correct ranges. Report: Give the ranges determined for Y , I, and Q.
d. Convert the YIQ image back to RGB format using the Matlab command
rgb_converted=ntsc2rgb(yiq_image)
Report your results.