CENG 391 – Introduction to Image Understanding Homework 1 solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

Download and extract the contents of ceng391 02T image formation.tar.gz.

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.
1