Warning 21.3.1.
Be patient with programs that modify images, they can take a little while to produce their results.
img = Image("cat.jpg") creates an Image object in the program that has all of the data from the image cat.jpg and names it with the variable img. Once we have done that, we can draw the entire image using lines of code like this:
win = ImageWin(img.getWidth(), img.getHeight()) # Make a window to hold the image
img.draw(win) # draw it in that window
for loop does - it takes a list of values and some instructions and runs the instructions for each one of the values. We can get a list of all the pixels with the procedure img.getPixels().
pixelList. Our for loop takes that giant list of pixels and one by one, calls the current one p and then does the body of the loop with it. After the loop is done, we make a window to display the image in and draw it - but don’t worry too much about that code - we want to focus on the loop and what it does to each pixel. This program changes the red value of each pixel to 0 - it removes all the red from the image, making it look like we are looking through blue-green glass.