# Need to import media to use it's functionsimport media### START OF FUNCTIONS # Set red channel on all pixels to 0def clearRed(picture):# Copy the input imagenew_pic = media.duplicatePicture(picture)# Loop through all the pixels in the copyfor pix in media.getPixels(new_pic):# Change the red channel valuemedia.setRed(pix, 0)# Return my edited picturereturn new_pic# Set the green channel on all pixels to 0def clearGreen(picture): new_pic = media.duplicatePicture(picture) for pix in media.getPixels(new_pic): media.setGreen(pix, 0) return new_pic# Set the blue channel on all pixels to 0def clearBlue(picture): new_pic = media.duplicatePicture(picture) for pix in media.getPixels(new_pic): media.setBlue(pix, 0) return new_pic# Manipulate multiple pixels to create a "sunset" effectdef make_sunset(picture):# Copy the input imagenew_pic = media.duplicatePicture(picture)# Loop through all the pixels in the copyfor p in media.getPixels(new_pic):# Set the blue and green channels to be 30% of their valuemedia.setBlue(p, media.getBlue(p) * 0.7) media.setGreen(p, media.getGreen(p) * 0.7)# Return my edited picturereturn new_pic# Darken an imagedef make_dusk(picture): new_pic = media.duplicatePicture(picture) for p in media.getPixels(new_pic):# Take a color and darken it (reduce all rgb values)color = media.makeDarker(media.getColor(p)) media.setColor(p, color) return new_pic# Brighten an imagedef make_sunny(picture): new_pic = media.duplicatePicture(picture) for p in media.getPixels(new_pic):# Take a color and brighten it (increase all rgb values)color = media.makeLighter(media.getColor(p)) media.setColor(p, color) return new_pic# Create a negative of an imagedef negative(picture):# Copy the input imagenew_pic = media.duplicatePicture(picture)# Loop through all the pixels in the copyfor p in media.getPixels(new_pic):# Set each color channel to be the difference # between the maximum pixel value (255) and # the current channel value.media.setRed(p, 255 - media.getRed(p)) media.setBlue(p, 255 - media.getBlue(p)) media.setGreen(p, 255 - media.getGreen(p))# Return my edited picturereturn new_pic## START OF TEST CODE # Filename of the image I wish to usefilename = 'gorge.jpg'# Load my image based on the filenamepicture = media.makePicture(filename)# Display changed images (DOES NOT SAVE THE IMAGE TO YOUR COMPUTER!)media.show(clearRed(picture)) media.show(clearGreen(picture)) media.show(clearBlue(picture)) media.show(make_sunset(picture)) media.show(make_dusk(picture)) media.show(make_sunny(picture)) media.show(negative(picture))# Cleans up media functionalitymedia.quit()