Mini-Lab: Using the CopyInto and CropPicture Functions

 


The objective of this mini-lab is to experiment with the copyInto and cropPicture functions.



Experimenting with Crop

Cropping an image means to cut out a certain part of the image and discard the rest of it. Actually, rather than change the original picture, cropPicture will create a new picture that consists only of the desired section, leaving the original picture unchanged. Cropping is one of the essential functions in image processing/manipulation. Understanding picture dimensions (height and width) is an important part of cropping an image.

Exercises:

Develop a toy program to learn about image processing. Follow the instruction below; adding the functions to your program in order to expand its functionality. Include your answers to the questions as doc string comments after each function.

  1. A list of support functions are provided for your convenience. You may have some of these functions available to you in jes4py, but the library contains some errors which are corrected in the support code. Copy the code for CropPicture into your main.py.

  2. Select a picture to use. You may name it whatever you like, but it will be referred to as myPict in these exercises.

  3. Type in and enter the line
    littlePic = cropPicture(myPict, 0, 0, 50, 50)

    What does littlePic look like? Which part of myPict is it?

  4. Now try the line:
    littleBiggerPic = cropPicture(myPict, 0, 0, getWidth(myPict)/2, getHeight(myPict)/2)

    What does this do? Which part of myPict is it?

  5. How would you crop the bottom-right quadrant of your picture? Write down your line of code. Test that your line of code works.

  6. Open myPict via the openPictureTool function. Find a section to crop by moving the mouse around over the picture. The x- and y- coordinates are displayed at the top. Write down the statement you would use to crop this section and save it in a variable. Test that your statement works.

 


Combining Crop and CopyInto

Exercises

Complete the following exercises to assess and expand the functionality of your program.

  1. Select another picture to use as a canvas. You may name it whatever you like, but it will be referred to as canvas in these exercises.

  2. Use the copyInto function to put littlePic from the previous exercises in the upper-left corner of canvas. Does this modify canvas?

  3. Try copying littleBiggerPic somewhere into the middle of canvas.

  4. Copy littlePic into littleBiggerPic, and then littleBiggerPic somewhere into an empty canvas. What does your code look like? Write it down.

Submit your answers

Submit the document containing your typed up answers to the questions on Kit. There is no program file to submit for this mini-lab.