Magick with Images
Ever since the first computers with graphical displays, computer editing and transformation of images has been one of the most popular application areas. There should be little surprise that there is a multiplicity of free graphic software available under Linux.
Many of the available packages are targeted towards specific applications: there are many graphics libraries available for programmers which address reading and writing specific file formats. There are also image viewers available which allow interactive editing as well. ImageMagick is different in that it provides a comprehensive set of tools which can be used interactively in the X Window System or command-line driven. These tools are based around a common library, written in C.
For those who want to go beyond the capabilities of the precompiled programs (see the sidebar “Getting ImageMagick”), the library is extensible to allow the addition of different image file formats. The library can also be used from your own programs through its well documented API. In addition, both Perl and Python interfaces are available to allow image manipulation from scripts.
If you want to try out some of the features of the ImageMagick tools, many of them can be used on-line via the Imaging Machine at http://www.vrl.com/Imaging/.
It is impossible for an article such as this to cover every aspect of ImageMagick; therefore, I have written a short description of each of the major programs. A very good set of on-line documentation can be found at the ImageMagick web site—it covers all aspects of using and programming the system.
The display program loads images from a file and displays them on the screen (see Figure 1). It has a large number of command-line options which make it very flexible. Display is ideal for running from a script for a presentation or demonstration and will show video as well as still images. Images can be manipulated in a variety of ways, either from the command line or interactively. Figure 2 shows a set of images (the original is in the top left hand corner) that illustrate some of the effects available. In each case, the settings used are the default settings for that effect.
The display program is quite similar to John Bradley's xv image viewer. To display an image, you can either select one interactively from the menus (see Figure 3) or at the prompt type the command:
$ display image.gif
In my research I work with many images in a raw format called YUV 4:1:1. This represents an image as a number of bytes. The YUV representation of an image is a combination of the luminance information in the image (a black and white version) called the Y component, and the chrominance information (the extra information required to make the black and white image into a colour image) called the U and V components. The Y component is thus made up of one unsigned byte per pixel in the image. Since the human eye is less sensitive to colour than luminance, the U and V components, each consisting of a number of signed bytes, are included at half the rate of the Y component. This gives a rather primitive form of lossy image compression compared to the more usual RGB representation where three unsigned bytes are used for every pixel in the image. In the examples here I will use a 176 by 144 pixel image. In order to display such an image, the following command can be used:
$ display -size 176x144\ image.yuvIn addition, if your image file has a header which is not among the supported types and you know that the image is in YUV format (this also applies to other raw formats), you can display it if you know the size of the header. For example, the following command:
$ display -size 176x144+16 image.yuvdisplays a raw YUV image, with a 16-byte header.
Import is an X image-capture program. It captures the contents of a target window, which may be specified in a variety of ways and stores it in a file. The captured image can then be viewed and manipulated with the following tools.
Animate, as its title suggests, displays an image sequence, which can be an MPEG file or a multi-image TIFF or MIFF file. The program works out the number of colours required to display the sequence before starting to play it so that the same palette can be used throughout to avoid interactions with colour schemes of the X Window System.
Montage combines several images into a single image. It is useful in preparing figures for papers and magazine articles, for example. There are options to annotate each image with text and to specify the background texture and colour and the border size. Figure 2 was created from the individual images by use of the montage program. The layout of the tiles and the labels were specified on the command line, and all other settings kept their default values.
Convert allows command-line conversion of images to and from many different formats. Its most common use is to convert to, and from, the ImageMagick MIFF format.
Mogrify provides a variety of different transforms which can be applied to images. A command-line interface to the transforms is available in the menus of the display program.
Identify prints all sorts of useful information about images, including a check on the completeness of the image and whether it is corrupt or not. Here is some example output:
$ identify image.gif image.gif 106x80+0+0 PseudoClass 256c 13453b GIF 2s
In this case the image is in GIF format image, 106 by 80 pixels in size, has a PseudoClass colour map with 256 colours, is 13453 bytes in size and took 2 seconds to process. The -verbose option prints a more comprehensive list of information including the colour map.
Combine allows you to combine images in all manner of different ways. It can also be used to create difference images from two input images to see how they differ. There are a variety of ways in which images can be combined in addition to these two.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Profiles and RC Files
- Astronomy for KDE
- Maru OS Brings Debian to Your Phone
- Understanding Ceph and Its Place in the Market
- Snappy Moves to New Platforms
- Git 2.9 Released
- OpenSwitch Finds a New Home
- What's Our Next Fight?
- The Giant Zero, Part 0.x
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide