Assignment #7: Images - Creation and Compression


Assigned: Monday, Nov. 12
Due: Monday, Nov. 19

Contents:


Overview

Topic: Images
Related Reading: Section 3.5 of the textbook, as well as our lecture notes on creating images in Python.


Internet Requirements

For some of the problems in this assignment, you will need to use Python. You can either use a Python run-time environment, such as available on the Mac computers in RH 225, or you can use the Python simulation environment, as desired.

In addition, you will need to download and install the XnView image viewer and converter for compressing images (and possibly for viewing images, depending on your environment -- it's not needed in the Linux lab).


Practice with Images

For these problems, be sure that you have downloaded and installed the XnView image viewer and converter for compressing (and possibly viewing) images.


Problems to be Submitted (25 points)

When you turn in your assignment, you must include a signed cover sheet with your assignment (you're assignment will not be graded without a completed cover sheet).

You are allowed to submit your assignment via email, but if you choose to do so, you must bring a hardcopy of your assignment along with a completed cover sheet to the instructor at the next class. (Note: Do not email the instructor any .zip file attachments, as SLU's email may not accept these emails, i.e. the instructor may not receive your email.)

Note: The problems assigned below are all very similar to one or more examples in the Practice Problems, so looking through all the Practice Problems is highly advised.

  1. (4 points)

    Similar to the Practice Exercises above, write a Python program that will draw a light gray image with a blue anti-diagonal line. In other words, the background should be light gray, and there should be a blue line connecting the bottom left corner to the top right corner of the image, like:

    Generate the actual image file for this image, and view it (e.g. with XnView) to verify that your program works correctly.

    Email this image file to the instructor, naming the file name as email_blue_antidiag.ppm, where email is your email login name (i.e. for the email address jdoe@slu.edu, the login name is jdoe, and the resulting file name would be jdoe_blue_antidiag.ppm).

    Be sure to hand in the code for your Python program with the rest of your assignment.

  2. (4 points)

    Similar to the Practice Exercises above, write a Python program that will draw a white filled box on an orange background. In other words, the background should be orange, and there should be a solid white box centered in the middle of the image. The size and shape of the box can be of your choosing, as long as it is at least 4 pixels on a side, and the orange background is visible on all sides (i.e. the box isn't flush with the edge of the image), and no orange is visible inside the box (the box is entirely white), like:

    Generate the actual image file for this image, and view it (e.g. with XnView) to verify that your program works correctly.

    Email this image file to the instructor, naming the file name as email_white_box.ppm, where email is your email login name (i.e. for the email address jdoe@slu.edu, the login name is jdoe, and the resulting file name would be jdoe_white_box.ppm).

    Be sure to hand in the code for your Python program with the rest of your assignment.

  3. (5 points)

    Similar to the Practice Exercises above, write a Python program that will draw an image with four equal-sized quadrants of four different colors. You may use any colors you choose, as long as the four quadrants are equal-sized and are clearly different colors, like:

    Generate the actual image file for this image, and view it (e.g. with XnView) to verify that your program works correctly.

    Email this image file to the instructor, naming the file name as email_color_quads.ppm, where email is your email login name (i.e. for the email address jdoe@slu.edu, the login name is jdoe, and the resulting file name would be jdoe_color_quads.ppm).

    Be sure to hand in the code for your Python program with the rest of your assignment.

  4. (5 points)

    Similar to the Practice Exercises above, write a Python program that will draw a red diagonally-shaded image, which progresses diagonally from black in the upper left corner to bright red in the lower right corner of the image, like:

    Generate the actual image file for this image, and view it (e.g. with XnView) to verify that your program works correctly.

    Email this image file to the instructor, naming the file name as email_red_diag_shaded.ppm, where email is your email login name (i.e. for the email address jdoe@slu.edu, the login name is jdoe, and the resulting file name would be jdoe_red_diag_shaded.ppm).

    Be sure to hand in the code for your Python program with the rest of your assignment.

  5. (7 points)

    Compare the quality of JPEG and JPEG-2000 compression at different degrees of compression.

    1. JPEG compression

      Download the image, Shed_in_Field.bmp.

      Similar to the Practice Exercises, generate compressed JPEG images. Generate five different JPEG-compressed images for Quality levels 40, 20, 10, 5, 2. Include the Quality level value in the name of each file for reference (i.e. name JPEG-compressed image at Quality level 10 as Shed_in_Field_q10.jpg).

      Compute the degree of compression for each of these five files. Indicate these degrees of compression, and discuss the trend with respect to the degree of compression as Quality decreases.

      Also, view the five compressed images. On a scale of 1-10 (1 is worst, 10 is best) indicate how well each of the compressed images compares with the uncompressed image. Indicate your scores for each, and discuss the trend with respect to the visual quality as Quality decreases.

    2. JPEG-2000 compression

      Download the image, Shed_in_Field.bmp.

      Similar to the Practice Exercises, generate compressed JPEG-2000 images. Generate five different JPEG-2000-compressed images for Quality levels 40, 20, 10, 5, 2. Include the Quality level value in the name of each file for reference (i.e. name JPEG-2000-compressed image at Quality level 10 as Shed_in_Field_q10.jp2).

      Compute the degree of compression for each of these five files. Indicate these degrees of compression, and discuss the trend with respect to the degree of compression as Quality decreases.

      Also, view the five compressed images. On a scale of 1-10 (1 is worst, 10 is best) indicate how well each of the compressed images compares with the uncompressed image. Indicate your scores for each, and discuss the trend with respect to the visual quality as Quality decreases.

    3. Overall, which compression method would you say is better? Why?


Extra Credit (3 points)

  1. (3 points)

    Similar to the Practice Exercises above, write a Python program that will draw the outline of a magenta triangle on a black background. The three corners of the triangle should be positioned at (row,column) positions: (10,20), (50,20), (10,50).

    Email this image file to the instructor, naming the file name as email_ctr_triangle.ppm, where email is your email login name (i.e. for the email address jdoe@slu.edu, the login name is jdoe, and the resulting file name would be jdoe_ctr_triangle.ppm).

    Be sure to hand in the code for your Python program with the rest of your assignment.