CS 4 Computer Science Bootcamp

CS 4 Computer Science Bootcamp
Summer 2018

Lab 6
In this lab, you will experiment with watermarking of images.

You will be using the Python module cImage.py, which we studied in class. "Right-Click and Save" this module to a folder on your desktop. Also, I wrote several functions for you to use, which are all found in a single program file water.py. Save this file into the same folder.

I also have three images for you to experiment:

Save these images into the same folder as well. You may also experiment with your own images, however they need to be GIF files.

The module cImage.py comes (built-in) with the following image and pixel functions:

  • im1 = FileImage("leo1.gif"): This function creates an abstract link to the image file "leo1.gif" and represents it in the program as "im1".
  • im2 = EmptyImage(n,m): This function creates an empty image data structure, which is of size nxm.
  • n = im1.getWidth(): This function returns the width (the number of columns) of the image "im1".
  • m = im1.getHeight(): This function returns the height (the number of rows) of the image "im1".
  • mywin = ImageWin("Test",n,m): This function creates a window of size nxm to draw images. The title of the window is "Test".
  • im1.draw(mywin): This function draws the image "im1" inside the window "mywin" starting from the left-top corner. If the image is smaller than nxm, the rest of the window will be empty. If the image is larger, it will be clipped.

  • Embed(x,y,k): This function places higher k bits of y into lower k bits of x, where x and y are 8-bit integers and k=1,2,3,4,5,6,7.
  • Extract(x,k): This function returns y such that higher k bits of y comes from lower k bits of x, where x and y are 8-bit integers and k=1,2,3,4,5,6,7.

  • MakeWaterMark(im1,im2,k): This function uses im2 as a watermark and places im2 into im1, such that the lower k bits of every color of every pixel of im1 comes from higher k bits of every color of every pixel of im2.
  • ExtractWaterMark(im1,k): This function extracts the lower k bits of every color of every pixel of im1 and creates a new image im2, and places these bits as color values of every pixel in im2.

Lab Instructions

The first 3 lines of the test program "water.py" contains statements to import the "cImage.py" functions to your development platform in order to use them.
import os
os.chdir("/Users/koc/Desktop/abc")
from cImage import *
Change the file path from above to the one you will be using.
This lab does not require a report. A demo to the TA is sufficient.