Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Portable Pix Map Image Format Specification The portable pix map image format (ppm) is one of the simplest methods of creating an image file.

C++

Portable Pix Map Image Format Specification The portable pix map image format (ppm) is one of the simplest methods of creating an image file. This format is encoded as readable ascii text or viewed as an image with an image viewing program such as gimp. Read the following wiki-link for additional details: https://en.wikipedia.org/wiki/Netpbm_format In this assignment, you will make a program that can convert color images to grayscale and black and white pictures and can create borders around the image. BE SURE TO READ THE DELIVERABLES!

Sample ppm file: \

P3

4 4

255

0 0 0 200 0 0 0 0 0 155 0 155

0 0 0 0 155 175 0 0 0 0 0 0

0 0 0 0 0 0 0 100 175 0 0 0

255 255 255 0 0 0 0 0 0 155 155 155

PPM Header

The ppm file is divided into a header and a body. The header contains four values:

P3

4 4

255

The first field with the value P3 is called a magic number. This defines what type of image is being represented:

Magic Number Image Type

P1 Black and White

P2 Grayscale

P3 Color

P3 indicates that the image will use RGB color. The second line indicates width and height. In this example, the image has a width of 4 and a height of 4. The 255 indicates the maximum color value. In the example above colors are between 0-255.

Problem 1: Working with Files The first milestone is to get the program to do the following:

Ask the user to specify the name of the ppm image file

If the file cannot be opened, the program should report this to the user and exit (ie return).

Ask the user to specify an output file.

Read the header information of the original file

Make an exact copy of the original ppm image data by looping through the rest of the file.

However, the program should only make a copy of the image if the image contains less than 1000 pixels for width or height. If the original image contains more than 1000 pixels for either dimension, then program should report this to the user and exit. (HINT: The header can help determine how many pixels are in the image.) Here is an Example interaction with the user:

Portable Pixmap (PPM) Image Modder

Enter image file name (ppm): fluffyBunny.ppm

Enter output image file name: out.ppm out.ppm created!

Note that the program is not required to display the image. It just manipulates pixels and creates a file in proper PPM format.

Problem 2:

The next milestone is to create a menu for the user to choose what image process to complete. Here is an example of the menu:

Portable Pixmap (PPM) Image Modder

Enter image file name (ppm): fluffyBunny.ppm

Enter output image file name: out.ppm

Image Processing Choices

: 1. Convert to grayscale

2. Invert Red

3. Invert Green

4. Invert Blue

5. Invert All

Enter Choice: 1 out.ppm created!

For now, just concentrate on creating the menu. The next milestone we will create the implementation for each option.

Problem 3: Invert Colors, Grayscale

The next milestone you complete is the implementations of menu options. These implementations will replace the simple copy you implemented in Milestone 1. Specifically, you will be adding some control structure to the loop you used to copy the image to determine what feature to execute.

Inverting Colors

Here is an example of how to invert a red pixel.

Assume colors are between 0-255.

If the red value of a pixel is 0, then the invert value is 255 (255 0 = 255)

If the red value of a pixel is 255, then the invert value is 0 (255 255 = 0)

If the red value of a pixel is 100, then the invert value is 155 (255 100 = 155 )

The same calculation is done for inverting blue and green

Grayscale Colors

To create a grayscale image, you take the average the values of all three color numbers for a pixel, the red, green and blue, and then replacing them all by that average. So if the three colors were 75, 250 and 25, the average would be 116, and all three numbers would become 116.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions