6.6 Summary

In this chapter we focused on cImage—a module that contains a number of objects that can be used to manipulate digital images. In particular, cImage includes the following objects:

  •    ImageWin

  •    EmptyImage

  •    FileImage

  •    Pixel

To process the pixels of an image, we used a pattern called nested iteration—that is, iteration inside iteration. Nested iteration allowed us to process all the pixels in a given row, column by column, before moving on to the next row. Using this iteration pattern, we implemented the following image processing algorithms:

  •    Negative images

  •    Grayscale images

  •    Resized images

  •    Flipped images

  •    Edge detection

In edge detection, we introduced lists of lists—that is, lists that are elements of lists.

We also introduced the notion of namespaces—collections of names available at a particular point in time. These namespaces are organized to allow Python to look up names when they are used, thereby making sure that there are no ambiguities. Along with describing namespaces, this chapter provided a more detailed consideration of the mechanics of parameter passing.

Key Terms

  • actual parameter

  • builtins namespace

  • call by assignment

  • convolution

  • digital image

  • digital image processing

  • edge detection

  • flip axis

  • flip image

  • flipping

  • formal parameter

  • grayscale

  • invocation

  • kernel

  • list of lists

  • local namespace

  • local variables

  • main namespace

  • namespace

  • negative

  • nested iteration

  • parameter passing

  • pixel

  • Pythagorean theorem

  • resizing

  • RGB color model

  • Sobel operators

Python Keywords, Functions, and Variables

  • _ _builtins_ _

  • dir

  • _ _name_ _

Programming Exercises

  1. 6.1     Write a program to create a collage. Your program should combine several images with different effects applied to the images.

  2. 6.2     Write a program to blend one image with another. You can try different techniques for combining the RGB values for two pixels, each from a different image.

  3. 6.3     Take a picture of yourself against a white background. Use the fact that you can “filter” out all the white pixels to place your picture in an interesting scene. This same process is used by weather forecasters on television; the only difference is that they stand in front of a solid blue or solid green background called a chromakey.

  4. 6.4     Another way to put yourself in an interesting picture is to take a picture of yourself against a relatively plain background, then take another picture of exactly the same background (use a tripod here with autofocus off) without you in it. Now you can compare the two images and remove the pixels that are exactly the same, or close to the same. Once you have removed those pixels, you can superimpose yourself on any background.

  5. 6.5     Using getMouse to get the coordinates of a pixel in an image, devise a way to remove the red-eye effect from the area of the image you click on.

  6. 6.6     Using getMouse, write a program that will allow you to “cut” a rectangular region out of an image and display it as a new image.

Design Credits: Calculator Icon made by Smashicons from www.flaticon.com

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.249.209