The Digital World-Lab 7


Assigned: March 16
Due: March 30

Once again, you will write several python programs.  The first is a simple utility for finding the maximum value of a list of three numbers.  The second and third ask  you to use the if statement and its relatives to create   interesting pictorial effects.

1. Write a function max3 that takes as arguments three numbers and returns the number with the largest value.  For example, after you write and load this function, if you type

    max3(4,-5,1)

in the command window, then you should see the result

    4.

Note:  There is a max function already built in to python!  You can just type max(4,-5,1) at the prompt.  But in this problem, you are asked to implement max3 from scratch, using only the if statement and its relatives to compare the values of two numbers.  Remember that the result you turn in should be a function with arguments and a return value, and thus should not itself read any input from the keyboard nor print any output.



2.  Write a program that takes a picture and creates a sepia-toned version.  This gives the picture the look of an antique photograph.  You first have to convert the picture to grayscale by averaging the red, green and blue components of each color.  You can then try enhancing the red component in each pixel, say, increasing it by 15%, and reducing the blue by 15%. A better algorithm is to treat the darker regions of the picture differently from the lighter regions. One book I have suggests that in the darker regions, where, say, the value of each pixel component is less than 64, the red should be increased 10% and the blue decreased by 10%, and that in the brightest regions (each pixel component greater than 191) the red should be increased by 8% and the blue decreased by 7%.  Continue to use 15% for the intermediate tones.  The original of an image, along with the result of applying the simple approach, as well as the more complex approach recommended here, are pictured below.



Your function should take a picture as the input argument, and return the sepia-toned picture.  Remember that the first step in this algorithm should be conversion to gray scale.  A good way to set up your file is to have two functions:  One just does the gray-scale conversion, and the other calls the gray-scale function.


3. Write a program that takes an image as picture, and returns a collage of four different versions of the image (For example, the four versions could be the original image, a mirror image, a grayscale version, a mirrored version, a pixellated version, etc. etc. You choose.  The example pictured below contains a grayscale version, a grayscale negative, and a "posterized" version that uses a limited palette of 8 colors.)  Each version should have half the dimensions of the original image.



EXTRA CREDIT.

4.  Write  a python program that convincingly turns Mona Lisa into a blond.  (You can use the Explore tool in JES to look at coordinates of pixels and their color components.)

As usual, put a comment with your name in each program.  E-mail to the grader  a zipped folder containing the program code, plus sample images for 2,3 and 4.