ImageMagick is a powerful tool for manipulating images that I use in photography and video. It is also complex, with a large repertoire of operations and settings, and I often forget how to produce a particular effect. So I have built up a collection of scripts that I call, or copy-and-paste into other scripts, as building blocks for larger projects. For my own convenience I started grouping them together in web pages, as cookbooks. Simple recipes that can be glued together to make banquets. Here are some of those pages.
They are intended to supplement, not replace, the official IM documentation and the Usage pages. I don't explain IM features that are explained on those pages. I don't compete with or replicate Fred's ImageMagick Scripts. Nor do I explain how to use Windows "bat" files, or Windows commands.
In these pages, IM scripts are mostly written in the Windows "bat" language. This has minor syntactic differences to bash and other Unix shells, and a "FOR" command that I use to loop through sequences and set variables. There is also some C code, mostly in the Process modules page, and some bash scripts.
The scripts often use %TEMP% for temporary storage, but sometimes use \temp\.
Most of the pages and scripts were originally written for IM v6 (eg %IM%convert); the newer ones were written for IM v7 (eg %IMG7%magick). I am slowly updating the code and scripts to use v7.
The scripts, code and ideas come with no guarantee whatsoever. If they don't work, tough luck. If they destroy your precious images, tough luck. If they destroy your hard disk and your computer catches fire, tough luck.
I suggest you set your browser such that it doesn't enlarge or reduce images. In Firefox, tick the box in menu option View, Zoom, Zoom text only.
The topics below are organised in the order they were first published, with the latest at the top. The later topics often build on material from the earlier topics. They are "living" pages, and some are frequently updated. The bottom of each page carries a "Page created" field; this is the timestamp of when the page was built.
Assuming that one image has been transformed to another by "-level", what were the parameters? more...
A simple program makes IM a non-stop background resource, a server for clients. more...
From a list of coordinates, a program orders them and makes paths in various formats. more...
Make an image that, when physically printed and bent into a cylinder, looks like a reference image. more...
Some standard near-power curves, aka transfer functions, tone or tone response or characteristic curves. more...
This has been promoted as a more "modern" version of CIE Lab, especially for high dynamic ranges. more...
Using dcraw to extract mosaic data, and exiftool to re-build a raw file. more...
When an image has two wobbly lines that are roughly horizontal, we can distort the image such that both lines become straight and horizontal. more...
Limiting pixel values to the min and max of a sliding window, or setting them to extremes. more...
When pixels have become out of gamut, how do we put them back in? more...
We reduce a chart of colour patches in a photo to one pixel per patch. more...
What -color-matrix or -function Polynomial will make one image look like another? more...
With four numbers, we can tweak the bottom, top and somewhere in the middle. more...
Setting lightness and contrast (and colour) without clipping, using power and sigmoidal-contrast. more...
Wobbly raster lines can be expressed as ordered sets of coordinates, and simplified to vectors. more...
IM can make images in the style of simple lithographs, halftone, silk-screen, etching, lino-printing, engraving and similar processes. more...
Searching quickly for the location of a small sub-image inside a much larger image. more...
Using FFT, we find relative rotation of images invariant to scale, translation, or other factors. more...
We experiment with RMS thresholds that classify image pairs as "same" or "different". more...
Experiments with IM's perceptual hash, with suggestions for improvement. more...
We replace each area of similar but varying colour with a single representative colour. more...
Skeleton images often contain stubs: short segments at the ends or along their length. This method removes them. more...
An image that has been built from smaller rectangular images can be segmented back into those images. more...
Brute-force alignment of corresponding levels of Gaussian pyramids finds a good translation-only alignment fairly quickly. more...
Images with transparency need special processing when making Laplacian pyramids. more...
Images can be blended by making Laplacian pyramids, blending these to make a third, and collapsing it. more...
When images have transparent areas, we can append such that opaque areas abut each other. more...
If a known image was composited with an unknown image making a known result, how can we find the unknown? more...
We can build an image by quilting together ragged-cut rectangles from a texture image. more...
Images can be assembled in grid patterns with minimum error boundary cuts. more...
An image can be cut by a single dark path to make a piece that will sit with small boundary error on another image. more...
An image can be cut by dark paths to make a ragged-edge piece that will tile with itself, in both shape and colour. more...
An image can be cut by up to four dark paths to make a piece that will sit with small boundary error on another image. more...
Dark paths solve some minimization problems, and create sequences for animation and other purposes. more...
A process module estimates colours for transparent pixels by cloning colours from elsewhere in the image. more...
We can tweak an image to match the brightness (and colour) and contrast of another. more...
The alignment of two images can be tested at every possible offset. more...
This page is automatically created by the script colCyclTst.bat. See Colour cycling: tests. more...
Cycling colours with different methods gives results that satisfy certain criteria. more...
From a given coordinate, we can find the nearest point in an arbitrary area. more...
Distorting polar coordinates (r,θ) is conveniently done by first transforming to Cartesian (y,x), distorting y or x, then transforming back. more...
How can we superimpose an image on to a coffee mug? If the mug can be modelled in POV-Ray, there are two obvious methods. more...
For simple image processing, writing the output can take a significant proportion of the overall time. more...
When an image has a wobbly line that is roughly horizontal, we can distort the image such that the line becomes straight and horizontal. more...
We can distort an image (perhaps representing fabric) so the central line follows an arbitrary path, and do the inverse. more...
A grayscale gradient image can be made more readable by showing contour lines, or lines perpendicular to contours. more...
The mid point of zero and an odd number is not an integer. So 50% gray, with integer IM, cannot be exactly 50%. more...
Two new features could be added to ImageMagick: -distort Triangulate and -sparse-colour Triangulate. more...
When histogram data is stored as images, we can manipulate it with image-processing techniques. more...
What are the best dcraw gamma and auto-brighten settings for various purposes? more...
Equalising an image is often useful, but can uglify photographs. When the contrast introduced by equalisation is limited, results are more pleasing. The process can be adapted across the image. more...
We can auto-level and auto-gamma as appropriate for different parts of an image, blending between these parts. more...
An image may have a number of variations, based on characteristics of the image divided into cells, or a regular crop. Then we want to blend these variations together. more...
We can do a linear transformation of levels by using either -level or +level, with a suitable change of parameters. For some situations, it isn't obvious which of these we should use. more...
JPEGs from cameras are often wider than they are high, with metadata that specifies the true orientation. But software often ignores this metadata, so viewers don't display or process as we would hope. This script normalises orientations. more...
Old documents often have little contrast between ink and paper. The paper may not be a constant colour or tone. We might want to prettify the document making it more visually attractive, or we might want to increase the legibility. We might want to make the paper white, and the ink black. more...
Digital blurring is usually Gaussian, or something close. Cameras defocus differently. more...
Resizing an image can create halo artifacts. These can be reduced by blending two results. more...
Images can be segmented (broken into pieces, clustered) according to the similarity of adjacent pixels. The GrowCut method grows clusters from pre-defined seeds according to the strength (or weighting) of cluster-membership. more...
We can customise ImageMagick to add new functionality, for example with -process using MagickCore, like plug-ins. I show some examples. more...
IM demo programs can be compiled with Cygwin tools. more...
IM can run under Cygwin, which provides a Unix-like environment under Windows. more...
Here is a process I use for detecting outliers in a series, such as the transformations from points in one image to points in another. By rejecting outliers, we improve the overall transformation. more...
Suppose we have an arbitrary black shape and an arbitrary black border. The shape is an "island"; it is surrounded by white. The black border extends to the image edges; it is a "mainland". more...
When the camera has twisted around the z-axis between photographs, registering the images is difficult. No areas in one image match areas in the other. We want to find alignment when the image has scaled, rotated, translated and perspectived. more...
When we have a list of interesting points in one image, we can locate matching areas in another image, making the assumption that any rotation and scaling is small. The assumption is true if the camera is hand-held but not moved much, such as frames from a video or stills intended for a panorama. more...
We can shift the colour temperature of an image (perhaps to compensate for light sources) by manipulating the colour channels. more...
For convenience, scripts and C functions are available in a single zip file. more...
In most digital cameras, each sensor element records either red or green or blue. These are arranged in a mosaic. A critical part of processing raw camera images is "demosaicing", which amounts to guessing suitable values for the other two channels at each pixel. more...
Given two images of the same size, where one image could be a translation of another image with a known scale and rotation, what are the best offsets? more...
Given one image that could be a rotation and scale of another image, what is the best rotation angle and scale factor? more...
Given one image that could be another image rescaled, what is the best scale factor? more...
Given one image that could be a rotation of another image, what is the best rotation angle? more...
Searching for the location of one image inside another is very easy. Doing it quickly is harder. more...
Detail draws the eye into a photograph, or distracts the gaze. It is also useful for aligning (registering) photos or video frames. more...
Sometimes a photograph needs more "zing", more "pop". Aesthetic decisions are difficult to quantify and harder to automate, but here are some tools aimed at large images derived from raw camera files. more...
We can displace a rectangular image so it appears to be on the face of a cylinder, or go in the opposite direction. more...
ImageMagick is a wonderful non-interactive tool for processing raster images. With Inkscape, it can do fancy things with text in SVG files. more...
I love GoPro cameras, including the fisheye effect (heavy barrel distortion). If we want, we can make the image rectilinear (removing this distortion). more...
ImageMagick has two colorspaces of particular importance: sRGB ("non-linear") and RGB ("linear"). Some people argue that operations should be performed in RGB space, not sRGB. This is my take on the subject. more...
Interactive image editors allow us to tweak a slider to adjust an effect. ImageMagick is non-interactive, but here are simple scripts to quickly see the effect of adjustments without needing complex Javascript or whatever. more...
This page is mostly about two-dimensional greyscale gradients, ranging from black to white, that have different values for both x and y dimensons. They are useful as masks for processing photographs, for video transitions, and a variety of graphics effects. more...
This is a method for moving pixels. For every destination pixel, we specify where it should be copied from. more...
ImageMagick has an infinite number of ways of converting a colour image to monochrome. However, it provides a smaller number of simple methods. more...
ImageMagick can change colorspaces. We can examine the effect of a round-trip from sRGB, to another colorspace, and back, both pictorially and numerically. more...
We can manipulate and combine compositions for new operations such as "equals" and "greater than". more...
ImageMagick can handle High Dynamic Range Images. It does this by storing and processing pixels as floating-point numbers instead of integers. more...
Here are some short Windows "bat" command files mostly using ImageMagick that I find useful for processing images. I use some as they stand, or copy and paste the commands into a more complex script. Some of these are used every day, and some are failed experiments. I have thrown them all together. You have been warned. more...
Sometimes we want to entirely remove an uneven border. In other words, we want to find a rectangle that contains a constant colour. more...
Gimp is a interactive image editor, useful for experimenting with effects and verifying results. It is limited to 8 bits per channel, which is a major limitation for serious processing. more...
We sometimes want to vary the amount of blur across an image, perhaps by using a mask: maximum blur where the mask is white, and no blur where the mask is black. more...
The pages are all works in progress, and I often add material. Each page has a "Page created" date at the bottom. This is automatically set when the page is rebuilt. It also has a "Page version", which I manually set when I make a significant change.
Not yet written:
Comments are not enabled on this page. Don't bother sending emails to this domain; I won't even see them.
I often hang out on the IM Forums at github.
If you have a comment or query about using ImageMagick, I encourage you to post it to that forum.
These pages don't carry adverts and don't use cookies.
This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.
Anyone is permitted to re-publish this page, but only for non-commercial use.
Anyone is permitted to link to this page, including for commercial use.
Page version v1.0 8-Nov-2014.
Page created 20-Aug-2024 12:16:35.
Copyright © 2024 Alan Gibson.