Converting an image to gray scale
import ImageWriter
# Load the image from a file
mypic = ImageWriter.loadPicture("souq_hd.jpg")
# Show the image on the screen
ImageWriter.showPicture(mypic)
# Get the width and height (in pixels) of the image
width = ImageWriter.getWidth(mypic)
height = ImageWriter.getHeight(mypic)
# Iterate over every pixel, changing each to a shade of gray.
# Note that the picture will NOT update on the screen automatically.
for i in range(width):
for j in range(height):
colors = ImageWriter.getColor(mypic, i, j)
theAverage = (colors[0]+colors[1]+colors[2])//3
ImageWriter.setColor(mypic,i,j,[theAverage,theAverage,theAverage])
# Update the picture on the screen.
ImageWriter.updatePicture(mypic)