Fill This Form To Receive Instant Help
Homework answers / question archive / Define a function named posterize
and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function developed in Chapter 7 and shown below, but it uses passed in RGB values instead of black.
def blackAndWhite(image): """Converts the argument image to black and white.""" blackPixel = (0, 0, 0) whitePixel = (255, 255, 255) for y in range(image.getHeight()): for x in range(image.getWidth()): (r, g, b) = image.getPixel(x, y) average = (r + g + b) // 3 if average < 128: image.setPixel(x, y, blackPixel) else: image.setPixel(x, y, whitePixel) An example of the program is shown below: