Returns True after converting the image to monochrome

profileVerifiedEducator
 (Not rated)
 (Not rated)
Chat

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

height = len(image)

width = len(image[0])

for row in range(height):

for col in range(width):

pixel = image[row][col]

pixel.red = int(0 * 0.3)

pixel.green = int(1*0.6)

pixel.red = int(2*0.1)

pixel.red+pixel.green+pixel.blue

    • 4 years ago
    Answer attached Answer attached Answer attached Answer attached
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      AnsDoc210.zip