Snigbo's ImageMagick pages

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

The scripts 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 roughly date order, with the latest at the top. The later topics often build on material from the earlier topics.

seamlpm_trailer.jpg

Seamless photomontage

Poisson image editing, and related techniques. more...

pinorpush_trailer.jpg

Pin or push

We can push pixels to new locations while pinning others in place. more...

slopes_trailer.jpg

Slopes

A simple scheme for creating, storing and processing slopes. more...

lith_trailer.jpg

Lithographic effects

IM can make images in the style of simple lithographs, halftone, silk-screen and similar processes. more...

srchimgag_trailer.jpg

Searching an image aggressively

Searching quickly for the location of a small sub-image inside a much larger image. more...

whatrotfft_trailer.jpg

By FFT, what rotation?

Using FFT, we find relative rotation of images invariant to scale, translation, or other factors. more...

sndvis_trailer.jpg

Sound and vision

Sound is an image with one dimension. more...

phashthresh_trailer.jpg

Perceptual hash thresholds

We experiment with RMS thresholds that classify image pairs as "same" or "different". more...

phashtest_trailer.jpg

Perceptual hash tests

Experiments with IM's perceptual hash, with suggestions for improvement. more...

flatcolcart_trailer.jpg

Flat-colour cartoons

We replace each area of similar but varying colour with a single representative colour. more...

partbound_trailer.jpg

Partition boundary masks

We partion an image into areas of flat or slowly-changing colour. more...

carttext_trailer.jpg

Cartoon and texture

An image can be deconstructed into a cartoon and texture. more...

find4corn_trailer.jpg

Find four corners

Three simple methods. more...

mendbrkln_trailer.jpg

Mending broken lines

Three methods are shown. more...

prunestubs_trailer.jpg

Pruning skeleton stubs

Skeleton images often contain stubs: short segments at the ends or along their length. This method removes them. more...

randline_trailer.jpg

Random lines

These are sometimes useful. more...

curve3d_trailer.jpg

Curving in 3D

We distort the image plane, like curving a piece of paper. more...

subimrect_trailer.jpg

Subimage rectangles

An image that has been built from smaller rectangular images can be segmented back into those images. more...

setmean_trailer.jpg

Setting the mean

We can tweak an image to match the brightness (and colour) of another. more...

mosaic_trailer.jpg

Mosaicing

We can make Bayer (mosaic) images from ordinary colour images. more...

aligngaus_trailer.jpg

Alignment by Gaussian pyramid

Brute-force alignment of corresponding levels of Gaussian pyramids quickly finds a good translation-only alignment. more...

lapalph_trailer.jpg

Laplacian pyramids with transparency

Images with transparency need special processing when making Laplacian pyramids. more...

detpyr_trailer.jpg

Detail by pyramids

Laplacian pyramids give us frequencies at which data occur. more...

blendpyr_trailer.jpg

Blending pyramids

Images can be blended by making Laplacian pyramids, blending these to make a third, and collapsing it. more...

squishimg_trailer.jpg

Squishing images

When images have transparent areas, we can append such that opaque areas abut each other. more...

invcomp_trailer.jpg

Inverse composites

If a known image was composited with an unknown image making a known result, how can we find the unknown? more...

quilt_trailer.jpg

Quilting

We can build an image by quilting together ragged-cut rectangles from a texture image. more...

dpassem_trailer.jpg

Assembling with dark paths

Images can be assembled in grid patterns with minimum error boundary cuts. more...

dpshape_trailer.jpg

Awkward boundaries with dark paths

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

dptile_trailer.jpg

Tiling with dark paths

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

dprect_trailer.jpg

Rectangle boundaries with dark paths

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

darkpath_trailer.jpg

Dark paths

Some minimization problems can be solved by finding dark paths. more...

haar_trailer.jpg

Haar wavelet pyramids

A blast from the past: Alfred Haar invented these in 1909. more...

fillholespri_trailer.jpg

Filling holes in priority order

Filling pixels in priority order improves quality. more...

fillholes_trailer.jpg

Filling holes

A process module estimates colours for transparent pixels by cloning colours from elsewhere in the image. more...

gainbias_trailer.jpg

Gain and bias

We can tweak an image to match the brightness (and colour) and contrast of another. more...

alignbf_trailer.jpg

Alignment by brute force

The alignment of two images can be tested at every possible offset. more...

fracnseanim_trailer.jpg

Fractal noise animations

Fractal or Perlin noise can be animated. more...

fracnse_trailer.jpg

Fractal noise

Fractal or Perlin noise is coherent and self-similar at different scales. more...

mspyr_trailer.jpg

Multi-scale pyramids

An image can be represented by a multi-scale pyramid. more...

animsrt_trailer.jpg

Animation with SRT

-distort SRT provides simple but high-quality animation. more...

Color cycle tests

This page is automatically created by the script colCyclTst.bat. See Colour cycling: tests. more...

colcycl_trailer.jpg

Colour cycling

Cycling colours with different methods gives results that satisfy certain criteria. more...

noise_trailer.jpg

Noise

+noise adds noise. Here are some illustrations. more...

nearcoast_trailer.jpg

Nearest coastal point

From a given coordinate, we can find the nearest point in an arbitrary area. more...

poldist_trailer.jpg

Polar distortions

Distorting polar coordinates (r,θ) is conveniently done by first transforming to Cartesian (y,x), distorting y or x, then transforming back. more...

coffmug_trailer.jpg

Coffee mug

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

spdsiz_trailer.jpg

Outputs: speed and size

For simple image processing, writing the output can take a significant proportion of the overall time. more...

strhoriz_trailer.jpg

Straightening horizons

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

followline_trailer.jpg

Follow line

We can distort an image (perhaps representing fabric) so the central line follows an arbitrary path, and do the inverse. more...

gradcont_trailer.jpg

Gradient contours

A grayscale gradient image can be made more readable by showing contour lines, or lines perpendicular to contours. more...

fiftypc_trailer.jpg

Fifty percent

The mid point of zero and an odd number is not an exact number. So 50% gray, with integer IM, cannot be exactly 50%. more...

triangul_trailer.jpg

Triangulation

Two new features could be added to ImageMagick: -distort Triangulate and -sparse-colour Triangulate. more...

histopeaks_trailer.jpg

Histogram peaks

When histogram data is stored as images, we can manipulate it with image-processing techniques. more...

gameql_trailer.jpg

Dcraw, gamma and eqLimit

What are the best dcraw gamma and auto-brighten settings for various purposes? more...

eqlimit_trailer.jpg

[Adaptive] Contrast-limited equalisation

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

algtile_trailer.jpg

Adaptive auto level and gamma

We can auto-level and auto-gamma as appropriate for different parts of an image, blending between these parts. more...

blendtile_trailer.jpg

Blending tiles

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

pango_trailer.jpg

Pango

ImageMagick can rasterise a simplified version of HTML. more...

canny_trailer.jpg

Canny edge detection

Canny (and other types of) edges can segment images. more...

levels_trailer.jpg

Levels

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

orient_trailer.jpg

Orientation

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 makes normalises orientations. more...

knots_trailer.jpg

Knots

We can draw pretty pictures of knots. more...

olddoc_trailer.jpg

Old documents

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

camblur_trailer.jpg

Camera blurs

Digital blurring is usually Gaussian, or something close. Cameras defocus differently. more...

sh2sh_trailer.jpg

Shape to shape

We can distort a shape to match another shape. more...

resamphm_trailer.jpg

Resampling with halo minimization

Resizing an image can create halo artifacts. These can be reduced by blending two results. more...

growcut_trailer.jpg

GrowCut segmentation

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

customim_trailer.jpg

Process modules

We can customise ImageMagick to add new functionality, for example with -process using MagickCore, like plug-ins. I show some examples. more...

compdemo_trailer.jpg

Compiling the MagickWand demonstration programs

IM demo programs can be compiled with Cygwin tools. more...

compim_trailer.jpg

Compiling IM with Cygwin

IM can be compiled with Cygwin tools. more...

cygwin_trailer.jpg

IM with Cygwin

IM can run under Cygwin, which provides a Unix-like environment under Windows. more...

Statistics

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

islands_trailer.jpg

Islands

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

alignpnt_trailer.jpg

Alignment by matching points

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

simpalign_trailer.jpg

Simple alignment by matching areas

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

coltemp_trailer.jpg

Colour temperature

We can shift the colour temperature of an image (perhaps to compensate for light sources) by manipulating the colour channels. more...

Zipped BAT files

For convenience, scripts and C functions are available in a single zip file. more...

demosaic_trailer.jpg

Demosaicing

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

whattrans_trailer.jpg

What translation?

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

whatrotscale_trailer.jpg

What rotation and scale?

Given one image that could be a rotation and scale of another image, what is the best rotation angle and scale factor? more...

whatscale_trailer.jpg

What scale?

Given one image that could be another image rescaled, what is the best scale factor? more...

whatrot_trailer.jpg

What rotation?

Given one image that could be a rotation of another image, what is the best rotation angle? more...

srchimg_trailer.jpg

Searching an image

Searching for the location of one image inside another is very easy. Doing it quickly is harder. more...

detail_trailer.jpg

Details, details

Detail draws the eye into a photograph, or distracts the gaze. It is also useful for aligning (registering) photos or video frames. more...

zingph_trailer.jpg

Adding zing to photographs

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

cylinder_trailer.jpg

Cylinders

We can displace a rectangular image to it apears to be on the face of a cylinder, or go in the opposite direction. more...

svgtext_trailer.jpg

SVG text

ImageMagick is a wonderful non-interactive tool for processing raster images. With Inkscape, it can do fancy things with text in SVG files. more...

debarrel_trailer.jpg

De-barrel distortion

I love GoPro cameras, including the fisheye effect (heavy barrel distortion). If we want, we can make the image rectilinear (removing this distortion). more...

graygam_trailer.jpg

Greyscale gamma: RGB/sRGB

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

panel9_trailer.jpg

Panel of Nine

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

gradients_trailer.jpg

Gradients Cookbook

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

displace_trailer.jpg

Displacement maps

This is a method for moving pixels. For every destination pixel, we specify where it should be copied from. more...

mmono_trailer.jpg

Making an image grayscale (monochrome)

ImageMagick has an infinite number of ways of converting a colour image to monochrome. However, it provides a smaller number of simple methods. more...

ckbkClut_trailer.jpg

Clut cookbook

ImageMagick uses a clut (Colour Look Up Table) to transform the colours of an image, channel by channel. From the input image, a red channel pixel value is used as an index into the clut image. The value in the red channel of the clut image is used as the new value for the red channel of the output image. The process is repeated for green and blue. more...

ckbkColSp_trailer.jpg

Colorspace cookbook

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

compcomp_trailer.jpg

Composite compositions

We can manipulate and combine compositions for new operations such as "equals" and "greater than". more...

snutf8_trailer.jpg

UTF-8 characters

ImageMagick can rasterise UTF-8 characters outside the ASCII range 0-127. more...

hdri_trailer.jpg

HDRI

ImageMagick can handle High Dynamic Range Images. It does this by storing and processing pixels as floating-point numbers instead of integers. more...

Snippets

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

colwheel_trailer.jpg

Colour wheels

We can draw some pretty colour wheels. more...

innertrim_trailer.jpg

Inner Trim

Sometimes we want to entirely remove an uneven border. In other words, we want to find a rectangle that contains a constant colour. more...

imgimp_trailer.jpg

Gimp and IM

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

selblur_trailer.jpg

Selective blur

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

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.

If you have a comment or query about using ImageMagick, I encourage you to put it on the ImageMagick Users Forum.

If you have a comment or query or error-report about snibgo's IM pages, feel free to reply to my announcement, or send a PM to me on that forum. I am user snibgo.

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 24-Nov-2016 18:42:34.

Copyright © 2016 Alan Gibson.