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

gblevel_trailer.jpg

Gain-and-bias and level

Converting between parameters for -level, +level and gain-and-bias. more...

whatlev_trailer.jpg

What level?

Assuming that one image has been transformed to another by "-level", what were the parameters? more...

cliserv_trailer.jpg

Client-server

A simple program makes IM a non-stop background resource, a server for clients. more...

poldistdir_trailer.jpg

Direct polar distortion

Distortion using polar coordinates directly. more...

raddist_trailer.jpg

Radial distortions

Shape to shape, and rectangle to shape. more...

shpcent_trailer.jpg

Shape centres

Various definitions. more...

acwise_trailer.jpg

acwise: ordering coordinates

From a list of coordinates, a program orders them and makes paths in various formats. more...

fxnew_trailer.jpg

New FX

Proposal for a replacement faster "-fx". more...

fxntest_trailer.jpg

New FX tests

Tests for a proposed faster "-fx". more...

fmttxt_trailer.jpg

ftxt: formatted text

A coder for reading and writing pixels as formatted text. more...

wrappipe_trailer.jpg

Wrapping a pipe

Make an image that, when physically printed and bent into a cylinder, looks like a reference image. more...

hdrtransfun_trailer.jpg

HDRI transfer functions

A cookbook of transfer functions for high dynamic range images. more...

nacluts_trailer.jpg

Non-absolute cluts

Cluts can be relative or proportional, and can have log scales. more...

logcluts_trailer.jpg

Log cluts

Applying log transformations to cluts. more...

transcrve_trailer.jpg

Standard transfer curves

Some standard near-power curves, aka transfer functions, tone or tone response or characteristic curves. more...

jzazbz_trailer.jpg

Jzazbz colorspace

This has been promoted as a more "modern" version of CIE Lab, especially for high dynamic ranges. more...

hotpixels_trailer.jpg

Hot pixels

Detecting and fixing. more...

camnoise_trailer.jpg

Camera noise

Where it comes from, and some methods to fix it. more...

procbay_trailer.jpg

Processing Bayer pixels

Using dcraw to extract mosaic data, and exiftool to re-build a raw file. more...

spescalut_trailer.jpg

Specify scaling by LUTs

Stretch/shrink controlled by a Nx1 image. more...

dispmsksrt_trailer.jpg

Displacement by masked SRT

A method for graduated distortion. more...

str2lines_trailer.jpg

Straightening two lines

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

trimtri_trailer.jpg

Trimming triangles

Remove virtual pixels added by some distortions. more...

fancyfr_trailer.jpg

Fancy frames

Making rectangular (or circular) frames from small elements. more...

colfring_trailer.jpg

Coloured fringes

... from chromatic aberration and other effects: causes and cures. more...

limminmax_trailer.jpg

Limit min-max

Limiting pixel values to the min and max of a sliding window, or setting them to extremes. more...

measblur_trailer.jpg

Measuring blur

Some metrics for blurriness. more...

jumpmeth_trailer.jpg

'Jump' method

How many colours do we need? more...

barrelpc_trailer.jpg

Barrels and pincushions

... and correcting them. more...

lincamraw_trailer.jpg

Linear camera raw

How linear is my camera raw data? How can I make it linear? more...

pntppl_trailer.jpg

Painting people

... or clothing or any modelled 3D object with arbitrary images. more...

maxloccol_trailer.jpg

Maximise local colour contrast

... without clipping. more...

maxloccont_trailer.jpg

Maximise local contrast

... without clipping. more...

adapcontblrshp_trailer.jpg

Adaptive contour blur and sharpen

The effect is along, or across, edges. more...

adapblrshp_trailer.jpg

Adaptive blur and sharpen

Modulating the effect by the existing sharpness. more...

softfoc_trailer.jpg

Soft focus: spreading the light

A common effect, if over-used. more...

strlinear_trailer.jpg

Stretch linear

When pixels don't reach 0 or 100%, how do we stretch them? more...

oogbox_trailer.jpg

Putting OOG back in the box

When pixels have become out of gamut, how do we put them back in? more...

dcrawwb_trailer.jpg

dcraw and WB

... (white balance) and clipping and contrast. more...

colchkcha_trailer.jpg

Colour checker charts

Tiny little images help us to correct grayness and colour. more...

findcard_trailer.jpg

Finding and analysing colour charts

We reduce a chart of colour patches in a photo to one pixel per patch. more...

col2mp_trailer.jpg

Colours to matrix and polynomials

What -color-matrix or -function Polynomial will make one image look like another? more...

powsmh_trailer.jpg

Power curve for shadow, mid and highlights

With four numbers, we can tweak the bottom, top and somewhere in the middle. more...

kcluster_trailer.jpg

K-clustering

A process module for k-means, fuzzy k-means and k-harmonic, with transparency. more...

sphaldcl_trailer.jpg

Sparse hald cluts

.. and completing them. more...

edithald_trailer.jpg

Editing with hald cluts

A brief introduction. more...

setmnsd_trailer.jpg

Set mean and stddev

Setting lightness and contrast (and colour) without clipping, using power and sigmoidal-contrast. more...

windmnsd_trailer.jpg

Windowed mean and standard deviation

Some methods: fast and slow, coarse and smooth. more...

crop2det_trailer.jpg

Crop to detail

A method for automatic cropping. more...

integim_trailer.jpg

Integral images

... for windowed mean and SD. more...

srt3d_trailer.jpg

Scale, rotate and translate in 3D

A simple but effective method. more...

watermark_trailer.jpg

Watermarks

Adding and removing them. more...

colcoords_trailer.jpg

Coordinates of a colour

What are the coordinates of pixels of a given colour? more...

linptcv_trailer.jpg

Lines, points and curves

Wobbly raster lines can be expressed as ordered sets of coordinates, and simplified to vectors. more...

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, etching, lino-printing, engraving 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 finds a good translation-only alignment fairly quickly. 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

Dark paths solve some minimization problems, and create sequences for animation and other purposes. 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 integer. 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 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 so it appears 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

Many methods for creating Nx1 Colour Look Up Tables. 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 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 04-Nov-2023 15:22:02.

Copyright © 2023 Alan Gibson.