Scientific Computing
Complete the setup to install the cImage
module and read some key differences based on the latest updates to the module.
Create a file called mouse.py
and save it to your cs100/ch6
folder. Save the following images to the same location with the name: lutherbell.gif and mickey.jpg.
from image import *
# get image
img = FileImage("lutherbell.gif")
width = img.getWidth()
height = img.getHeight()
# create window
myWin = ImageWin(width, height, "Awesome Image")
# display image on window
img.draw(myWin)
# print out RGB values of pixel based on where mouse clicks
x,y = myWin.getMouse()
p = img.getPixel(x,y)
print("Pixel values: ", p.getRed(), p.getGreen(), p.getBlue())
# exit window when user clicks on any part of it
myWin.exitOnClick()
Modify the script to display the Mickey Mouse picture.
Display Mickey with blue shoes instead of yellow ones. Hint: go through each pixel and compare how close it is to the color yellow (you’ll need to play with what it means for a pixel color to be ‘close enough’).
Write a function negative(p)
that receives a pixel and returns its corresponding negative pixel. Then use this function to create the negative picture of your Mickey Mouse.
x
as the red, green, and blue values, where x
is an average of the original RGB values.Submit your working mouse.py
to Moodle AND INCLUDE THE IMAGE YOU USED.