Image Processing with QccPack and Python

How to use QccPack to manipulate images with Python in code and from the Python prompt.
Essential Packages

Python, xv and the PIL package are essential for Python image processing programming. Run these commands to build PIL in Linux:

python build_ext -i

Working with the Python Imaging Library

The most important class in the Python Imaging Library is the Image class, defined in the module with the same name. We create instances of this class in several ways: by loading images from files, processing other images or creating images from scratch.

To load an image from a file, use the open function in the Image module:

>>> import Image
>>> im = Image. open ("lenna.ppm")

The Python Imaging Library supports a wide variety of image file formats. The library automatically determines the format based on the contents of the file or the extension.

The next example (Listing 2) shows how the Image class contains methods to resize and rotate an image.

Color Transforms

The Python Imaging Library allows you to convert images between different pixel representations using the convert function—for example, converting between modes:

im ="lenna.ppm").convert ("L")

The library supports transformations between each supported mode and the L and RGB modes. To convert between other modes, you may have to use an intermediate image.


The ImageFilter module contains a number of predefined enhancement filters that can be used with the filter method. For example, from the Python prompt, do the following:

>>> import ImageFilter
>>> out = im.filter(ImageFilter.DETAIL)

Once you have imported the module, you can use any of these filters:

  • ImageFilter.BLUR

  • ImageFilter.CONTOUR

  • ImageFilter.DETAIL

  • ImageFilter.EDGE_ENHANCE


  • ImageFilter.EMBOSS

  • ImageFilter.FIND_EDGES

  • ImageFilter.SMOOTH

  • ImageFilter.SMOOTH_MORE

  • ImageFilter.SHARPEN

Controlling the Decoder

Some decoders allow you to manipulate an image while reading it from a file. This often can be used to speed up decoding when creating thumbnails and printing to a monochrome laser printer. The draft method manipulates an opened but not yet loaded image so it matches the given mode and size as closely as possible. Reconfiguring the image decoder does this. See Listing 3 for an example of how to read an image in draft mode.

Listing 4 shows how the ImageDraw module provides basic graphics support for Image objects.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

image processing with scripting language

image processing's picture

Python Imaging Library have great features and your blog is like a teacher where every information is very vital and informative for me.thanks a lot providing me such kind of information.

image processing

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState