Image Processing with QccPack and Python

 in
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 setup.py build_ext -i
python selftest.py

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 = Image.open("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.

Filters

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.EDGE_ENHANCE_MORE

  • 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.

______________________

Comments

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.

Regards,
image processing

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix