Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 0 . Add Sepia Conversion Sepia was a process used to increase the longevity of photographic prints. To simulate a sepia - toned photograph,

10. Add Sepia Conversion
Sepia was a process used to increase the longevity of photographic prints. To simulate a sepia-toned photograph, you darken the green value to int(0.6* brightness) and blue value to int(0.4* brightness), producing a reddish-brown tone. Extend your implementation of mono to include the case when sepia is True. Use an if-statement to make sure that you do not break grayscale conversion. Your function should produce normal grayscale when sepia is False and sepia tone when it is True.
To test out sepia tone, you will need to execute pictool.py with the sepia option, adding --sepia=True to the end of the command line. For example, executing the command
python pictool.py mono images/Walker.png Walker2.png --sepia=True
should perform the following conversion:
# IMPLEMENT THESE FOUR FUNCTIONS
def mono(image, sepia=False):
"""
Returns True after converting the image to monochrome.
All plug-in functions must return True or False. This function returns True
because it modifies the image. It converts the image to either greyscale or
sepia tone, depending on the parameter sepia.
If sepia is False, then this function uses greyscale. For each pixel, it computes
the overall brightness, defined as
0.3* red +0.6* green +0.1* blue.
It then sets all three color components of the pixel to that value. The alpha value
should remain untouched.
If sepia is True, it makes the same computations as before but sets green to
0.6* brightness and blue to 0.4* brightness.
Parameter image: The image buffer
Precondition: image is a 2d table of RGB objects
Parameter sepia: Whether to use sepia tone instead of greyscale
Precondition: sepia is a bool
"""
# We recommend enforcing the precondition for sepia
# Change this to return True when the function is implemented
assert type(sepia) is bool
height = len(image)
width = len(image[0])
for row in range(height):
for col in range(width):
pixel = image[row][col]
brightness =0.3* pixel.red +0.6* pixel.green +0.1* pixel.blue
pixel.red = int(brightness)
if sepia:
pixel.green = int(brightness *0.6)
pixel.blue = int(brightness *0.4)
else:
pixel.green = pixel.red
pixel.blue = pixel.red
return True

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions