Write a program that converts a color image to grayscale. The user supplies the name of

Chapter 8, Problem 14

(choose chapter or problem)

Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in. You will probably want to go back and review the Image object from the graphics libarary (Section 4.8.4). The basic idea for converting the image is to go through it pixel by pixel and convert each one from color to an appropriate shade of gray. A gray pixel is created by setting its red, green, and blue components to have the same brightness. So color _rgb ( 0, 0, 0) is black, color _rgb (255, 255, 255) is white, and color _rgb ( 127, 127, 127) is a gray "halfway'' between. You should use a weighted average of the original RGB values to determine the brightness of the gray. Here is the pseudocode for the grayscale algorithm: for each row in the image : for each col11mn in the image : r, g, b = get pixel information for current row and column brightness = int(round(0.299r + 0.587g + 0.1 14b)) set pixel to color_rgb(brightness, brightness, brightness) update the image # to see progress row by row Note: The pixel operations in the Image class are rather slow, so you will want to use relatively small images (not 12 megapixels) to test your program.

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back