Tutorial for first year computer science students

Back to Tutorials

Final Exercises

Download the Medialib ex11 files from the gallery.

Exercise 1: Image Processing

  1. Load and draw each pixel of a full color .ppm (Portable Pixel Map) image, and show the RGB histograms of the image using the rect() function of MediaLib to draw each vertical bar.
  2. MediaLib Exercise
  3. Convert the color image to a grayscale image using the following formula and save it to a .pgm (Portable Gray Map) file: Gray = 0.299 * Red + 0.587 * Green + 0.114 * Blue
  4. Load and draw each pixel of the grayscale image and show its RGB histograms
  5. MediaLib Exercise
  6. Apply a 3x3 median filter to the grayscale image and save it to a .pgm file. The median filter is a non-linear digital filtering technique, often used to remove noise from an image or signal. Use the median() function of statistics module to get the median out of a list. Note: The median filter cannot be applied to the first/last row and the first/last column. Simply fill in the first/last row and the first/last column with 0s or 255s (black or white).
  7. Load and draw the filtered grayscale image and show its RGB histograms
  8. MediaLib Exercise


Exercise 2: Pizza Game

Design and develop the user interface and user interaction that can let the user to make a pizza simply with mouse clicks. For example:

  1. Show two pizza images for the user to select
  2. Show the selected pizza base and the images of materials
  3. When the user click the material, it will be selected
  4. When use click on the pizza base, draw the image of the material at the position of the mouse click

It is not necessary to follow the example. You may design a more interesting game.

An example of simple mouse interaction for the selection from two pizzas is given in the code file “final_ex2.py”. However, this can be refined so that:

  1. When the mouse click is out of the pizza, the material should not be drawn.
  2. The mouse click position is the center (instead of the top-left point) of the material image to draw.
Pizza Game


Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.