Question: using python write a program that modifies a ppm image in one of the following ways (1) negates the colors, (2) applies high contrast, (3)

using python write a program that modifies a ppm image in one of the following ways (1) negates the colors, (2) applies high contrast, (3) applies a grayscale (4) removes a color (either red, green or blue) (5) applies three different modifications to each of the thirds of the image; you choose what three of the four modifications you apply and whether the thirds are vertical or horizontal

you have to prompt the user to enter the input ppm file name; you have to check and make sure the file is of appropriate ppm type (P3) and max RGB values(255) and you have to prompt the user for the output ppm file name; prompt the user for one of the commands to know what modification to apply; the user will enter the command and the program has to apply the modification associated with the command, write the modified image to the output file and exit the program, if the user enters a command that is not there alert them and show the menu again, if the user makes three failed attempts alert them and exit the program

you need to define: (1) one fuction, with two paramaters one for the infile and one for the outfile, that writes the first three lines(the first three lines are considred the header of the file the first line is the specification which should be P3 if not exit the program, the second line is the pixel columns and rows in the file, the third line is the max value of red green and blue in the picture the max value is 255) of the input image to the output image(no need to modify those lines) infile and outfile are file objects not names of the files if a line starts with # ignore it (2) one function, with three parameters one for the infile, one for the outfile, and one fore the modifiction, this one needs to be called after processing the header of the input file, it goes through each line in the body of the infile and modifies the rgb values according to the modification then writes the modified output image (3) one function that takes in a single integer in the range 0 to 255 and returns its color negation to find the negation you subtract the integer from 255 (4) a function that takes in a single integer in the range 0 to 255 and returns its high contrast for high contrasts if the integer is less than or equal to 127 set it to 0 and if greater than 127 set it to 255 (5) a function that takes in three integer values each in the range 0 to 255 and returns one single integer the represents the grayscale of the color (6) a function that takes in three rbg values in the range 0 to 255 and a string that represents the color you want to remove (either red, green or blue) and returns a tuple that consists of three integer values

DO NOT USE GLOBAL VARIABLES

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!