CSC111 Homework 5 2011

From dftwiki3
Revision as of 12:32, 23 October 2011 by Thiebaut (talk | contribs) (Inspiration)
Jump to: navigation, search

--D. Thiebaut 09:05, 18 October 2011 (EDT)


Hw5solClooney.png







This assignment is due on Tuesday evening, Oct. 25th, at midnight. You can work on it in pairs, or individually. Make sure you submit 3 files when you are done with this assignment.


Automatic Picture Editor

Overview

  • Your assignment is to write a graphics program that takes a picture of you and modify it by apply several different transformations, in fashion similar to what we did to poor George Clooney (see program).
  • The challenging part is that your program should work for pictures of different geometry, and with different captions (more on that later).

Preparation

  • It will be easier if you do not use beowulf for this assignment. Use a computer in the lab, or your own computer to perform the work on this assignment.
  • Select a picture of yourself that is in the area of 300 by 200 pixels (if possible). Don't select something that is 1000 by 1000 or your program will take forever to process it and you will waste a lot of time debugging.
  • The picture must have a gif extension, otherwise the graphics.py library will not be able to load it. Very likely the picture you will have of yourself will have a jpg, jpeg, or png extension. That's ok, you can transform it to a gif extension by uploading it to this Web site and downloading the gif version: www.coolutils.com
  • Once you have the picture, put it in the same directory (folder) where your python program will reside.
  • Make sure the graphics.py library is there as well.
  • Find out the width and height of your image (use Google to help you figure out how to do this with Windows or Mac OSX, or use a simple utility I have put together for this purpose).
  • Then create a short python module, called userInfo.py. Make sure you spell it exactly as shown, as your program wil be tested with a userInfo.py module of my own.


 # userInfo.py
 # module containing information about a gif file
 # to be process by hw5.py
 filename = "alexandra.gif"
 caption = "Alexandra"
 width = 400
 height = 300


Of course, you will have to replace alexandra in the file name and caption to what you picked for your file name and your caption.
  • You are now ready to write hw5.py, a python program that will import everything from the userInfo.py module, and use it to conduct its transformation.
  • Here's a debugging version of hw5.py that will help you figure out how things will work.


# hw5.py
# your name

from userInfo import *
from graphics import *

def main():
    print( "Gif file: ", filename )               # this will print alexandra.gif
    print( "width of gif file: ", width )        # this will print 400
    print( "height of gif file: ", height )      # this will print 300
    print( "User name: ", caption )            # this will print Alexandra

main()



Your assignment

  • You are now ready to start programming
  • Here is a list of the different transformations your program will have to perform:
    1. The demo program I used to pixelate Clooney is not very robust. It will crash if the size of the square (sq) does not divide the width or height exactly. You will have to fix this so that your program can work with any value of width and height.
    2. Your program will put a border around the picture. The border should be at least 5 pixels wide, and be drawn using 2 different colors (at least).
    3. Your program should use some pixelation operation (similar to what we did with Clooney) to modify the face of the person in the image (but not the border!). You can use one of the methods we demonstrated in class, or come up with your own.
    4. Your program will display the caption inside the border, centered relative to the width of the image, and either at the top, or at the bottom of the frame. The text of the caption is the contents of the caption variable in the userInfo module.
    5. Your program will perform some RGB transformation of the image (but not of the frame or the caption). Use your imagination for the type of RGB transformation. The last lab shows you several options.
    6. The order in which your program will carry out the operations is not necessarily the same as the order in which they are listed here!
  • In addition, you will have to make sure that every transformation your program carries out on the image uses only the variables width and height that are defined in userInfo.py, because your program will be tested not only with the gif file you will upload, but also with an other gif file that will be defined in a different userInfo.py. In other words, I will have a gif file different from yours, say 111test.gif, and a different userInfo.py module that will contain the width and height of 111test.gif, with a caption such as 111a test caption, and I will put both of them in the same folder with your program, and I will launch your program. If your program is written correctly it will put the right border, right caption, and will apply the right transformations to the test image.
You can test your program by creating a second gif file of different width and height as your first image, and a new userInfo.py file, and see if your program works without having you to change it for the new image.

An Example

  • Below is an example of what your program could do. For this example I have pixelated the image using squares while transforming the colors to black and white, added two borders, and placed the caption "George Clooney" in the bottom border. Feel free to use different transformations. For your information, you can transform an image to black and white by setting the RGB values to the average of their values, i.e. R = G = B = (R+G+B)//3. (Note: the size of the graphics window for the image below was 600 by 400.)


Hw5solClooney.png


  • The userInfo.py file for this output is
# userInfo.py
 # module containing information about a gif file
 # to be process by hw5.py
 filename = "Clooney.gif"
 caption = "George Clooney"
 width = 600
 height = 400

Submission

  • You have to submit three files:
    • hw5.py,
    • userInfo.py,
    • and your gif image file.
  • If you forget any one of these files, your program will crash when I run it, and your grade will be at most a C-.
  • Use the online submission form to submit your files: submit5

Grading

  • Up to 2/3 extra points will be given to imaginative designs (both for the graphics, and for the code).
  • Up to a point will be removed for missing or incomplete documentation. Look at the posted solutions for previous Homework assignments to see examples of good documentation.
  • A program that works on the user-supplied image, but not on the instructor supplied image will be worth at most B.
  • A program that crashes when it runs will be worth at most C-.



Inspiration

(Section added on 10/23/11)

  • Here are some portraits that involve some computer alteration. Some of them are more complex than what we can do with this assignment, but the idea here is to give you some inspiration! :-)

CSCPixelationPortrait0.png CSCPixelationPortrait1.jpg CSCPixelationPortrait2.jpg CSCPixelationPortrait3.jpg CSCPixelationPortrait4.jpg CSCPixelationPortrait5.jpg CSCPixelationPortrait6.jpg CSCPixelationPortrait7.jpg CSCPixelationPortrait8.jpg CSCPixelationPortrait9.jpg CSCPixelationPortrait10.jpg CSCPixelationPortrait11.jpg CSCPixelationPortrait12.jpg CSCPixelationPortrait13.jpg


...