Starting from:

$25

CENG391 -  Introduction to Image Understanding  - Homework 1 - Solved

 Exercise 1              Color Support for the ceng391::Image Class
Modify the contents of the Image::write  pnm function so that instead of writing an error message for RGBA images, it saves the image contents in the binary PPM format. Hint: You should only write the RGB values into the file. The alpha values should not be saved. This means you will need two loops instead of one.

         Exercise 2            Loading PNM Images
Write a new member function Image::read pnm that takes a std::string argument named filename. The function should try to open the file with the given name and read its contents if its contents are in the PGM or PPM binary formats. When reading color images, remember to create a four channel RGBA image. You should read the RGB values from the file and initialize all alpha values to 255.

         Exercise 3           Color Conversion
Write two new member functions Image::to grayscale and Image::to  rgba, that converts the image contents from grayscale to RGBA and vice versa. If the image is already of the target format the functions should return immediately.

To convert from grayscale to RGBA, just copy the gray value to all the color and alpha channels. To convert from RGBA to grayscale, you can use the following set of formulas:

IGray(x,y) = IRed(x,y) ∗ 0.3 + IGreen(x,y) ∗ 0.59 + IBlue(x,y) ∗ 0.11;

Before writing back the grayscale value, you should check for underflow and overflow and you should discard the alpha values.

More products