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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question
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 3 steps

Blurred answer
Knowledge Booster
InputStream
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L