for my python class I am to write a program to modify immages. the image format being used is a PPM. the PPM image format is encoded in human readable plan text. PPM image has two parts (1. header and 2. body

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

for my python class I am to write a program to modify immages. the image format being used is a PPM. the PPM image format is encoded in human readable plan text. PPM image has two parts (1. header and 2. body

 

PPM Body
Below the header is the body of the PPM file. Each pixel has a red,
green, and blue value as indicated by an integer number between 0 and
255. For example, the pixel with a RGB value of (255, 0, 0) represents
the color Red.
Example PPM Image
Download the PPM image of the NY sky line. You can open the
image with a PPM image reader software such as Ifranview. The image
file can also be opened as plain text in a text editor, which allows us to
edit the image.
Tasks:
Write a program to modify a PPM image in the following ways:
1. Negate the colors in the image
2. Apply a high contrast to the image
3. Apply a gray scale to the image
4. Remove a primary color (red, green, blue) from the image
Your program should follow the steps below:
1. Prompt the user to enter the input PPM file name, the output PPM file name, and one of the following commands to determine what modification should be applied to the input PPM image so that the modified image is stored in the output PPM file:
A. "negate"
B. "high contrast"
C. "gray scale"
D. "remove <color>" where <color> is "red", "green", or "blue"
2. Apply the image modification based on the user command. You must define the functions mentioned below to perform the image
modification. Note that the original image file should not be changed; the modified image must be stored in the output PPM image file name. Also note that the output file should have the same header lines as the input file.
a. negate_image(): accepts the input image file object and the output image file object as arguments. For each pixel element in the input file, it takes the value, subtracts 255 from it and takes the absolute value of the result. This result is written to the output file.
b. high_contrast_image(): accepts the input image file object and the output image file object as arguments. For each pixel element in the input file, if the value is higher than 127, set it to 255 or else set it to zero. This result is written to the output file.
c. gray_scale_image(): accepts the input image file object and the output image file object as arguments. For each element in a RGB triplet (consecutive three elements) in the input file, convert its value to the triplet’s average. The result is written to the output file.
d. remove_red_image(): accepts the input image file object and the output image file object as arguments. This function sets all red values to 0 (red is the 1st value in an RGB triple). The result is written to the output file.
e. remove_green_image(): accepts the input image file object and the output image file object as arguments. This function sets all green values to 0 (green is the 2nd value in an RGB triple). The result is written to the output file.
f. remove_blue_image(): accepts the input image file object and the output image file object as arguments. This function sets all blue values to 0 (blue is the 3rd value in an RGB triple). The result is written to the output file.
3. Test the output of the above functions by displaying the modified image with a PPM image reader software such as Ifranview.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage