#---------------------------------------------------------------------- # Program to illustrate simple image processing # # Copyright (C) February 10, 2017 -- Dr. William T. Verts #---------------------------------------------------------------------- def Main(): Filename = pickAFile() Canvas = makePicture(Filename) show(Canvas) for Y in range(getHeight(Canvas)): # Scan every line of the image for X in range(getWidth(Canvas)): # Scan every pixel within a line PX = getPixel(Canvas, X, Y) # Pick up a pointer to pixel at # Pick up the values of the current pixel R = getRed(PX) G = getGreen(PX) B = getBlue(PX) # Modify the current values (uncomment the # section for the desired effect). # Brighten the Pixel # R = R + 20 # G = G + 20 # B = B + 20 # Darken the Pixel # R = R - 20 # G = G - 20 # B = B - 20 # Negate the Pixel # R = 255 - R # G = 255 - G # B = 255 - B # Convert to Gray Scale # Brightness = (R + G + B) / 3 # R = Brightness # G = Brightness # B = Brightness # Convert to Black & White # Brightness = (R + G + B) / 3 # if (Brightness > 128): # R = 255 # G = 255 # B = 255 # else: # R = 0 # G = 0 # B = 0 # Convert to 8-color RGB # if (R > 128): # R = 255 # else: # R = 0 # # if (G > 92): # G = 255 # else: # G = 0 # # if (B > 128): # B = 255 # else: # B = 0 # Update the pixel with the new values setRed(PX,R) setGreen(PX,G) setBlue(PX,B) # Show the changes on screen after each line repaint(Canvas) return