Fred's ImageMagick Scripts


    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at:


Creates the cepstrums to depict the type, amount and orientation of camera type blurring in an image.

Download Script

last modified: July 19, 2015

USAGE: cepstrum [-s size] [-o overlap] [-r rolloff] [-c constant] [-G] infile outfile
USAGE: cepstrum [-h or -help]

-s ... size ........ percent size of original image to use for the
.................... dimension of regions; 0<integer<100; default=25
-o ... overlap ..... percent overlap of regions; 0<=integer<100; default=50
-r ... rolloff ..... cosine-bell window rolloff in percent for the regions;
.................... 0<integer<100; default=40
-c ... constant .... constant value used in log operation; integer>0;
.................... default=10000
-G ................. create grayscale cepstrum

PURPOSE: To create the cepstrum to depict the type, amount and orientation of camera type blurring in an image.

DESCRIPTION: CEPSTRUM creates the cepstrum of an image to detect its blurring type, amount and orientation. The cepstrum is generate by first computing a running average of the magnitude of the Fourier Transform from a complete set of subsections of the image each of which is windowed using typically about a 40% cosine-bell rolloff to black. The windowing is done to help assure that each subsection conforms to the Fourier Transform assumption that the image is periodic. The negative log is applied to this running average, which is then stretched to span the full dynamic range. Finally, this result is treated as the real component and combined with a black image for the imaginary component and inverse transformed back to the spatial domain. The name cepstrum is derived from the word spectrum, but with the first four letters reversed. It is in some sense a spectrum formed backwards. Any alpha channel on the image will be removed automatically before processing.

For lens defocus, the cepstrum should produce a white ring in a generally dark background. The diameter of the white ring is equivalent to twice the diameter of the defocus amount.

For motion blur, the cepstrum should produce an array of dots on a line oriented at the angle of the motion blur. The distance between the two dots closest and on each side of the center of the cepstrum image is equivalent to twice the amount of motion blur.


-s size ... SIZE of sub-regions used to generate the cepstrum expressed as percent of original image dimensions. Values are integers such that 0<size<100. The default=25

-o overlap ... OVERLAP is the percent overlap of the sub-regions used to generate the cepstrum. Values are integers such that 0<=overlap<100. Zero indicates that the sub-regions do not overlap. The default=50. The number of regions processed will be approximately ((100/overlap)*(100/size)-1)^2. With size=25 and overlap=50, this amounts to approximate 49 regions.

-r rolloff ... ROLLOFF is the cosine-bell shaped windowing fuction rolloff in percent of the image dimensions used to taper the sub-regions from full image intensities to black near its edges. Values are integers such that 0<rolloff<100. The default=40.

-c constant ... CONSTANT is the multiplier value used in the log enhancement. Smaller values attenuate noise more than larger values. Values are integers>0. The default=10000

-G ... Creates GRAYSCALE cepstrum by converting the input image to grayscale before processing.

REQUIREMENTS: IM version 6.5.4-7 or higher, but compiled with HDRI enabled in any quantum level of Q8, Q16 or Q32. Also requires the FFTW delegate library.

See Fourier Transform with ImageMagick, for more details.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


15 pixel Lens Defocus

Blurred Input
(see script, fftconvol)

-c 20000

Red Circle Overlaid
With Diameter = 30
Radius = 15

15 Pixel Motion Blur At -45 Degree Angle to Horizontal

Blurred Input
(see script, fftconvol)

-c 5000

Red Line Overlaid
With Length = 30
Half Length = 15

What the script does is as follows:

  • Creates multiple subsections of the image, each nominally at
    at 1/4 of the width and height with 50% ovelap
  • Multiplies each subsection by a cosine-bell roll-off mask
    to taper the image to black near its edges
  • Transforms each subsection to the frequency domain using -fft to
    get the magnitude component
  • Computes the average of all the subsection magnitude images
  • Applies a scaled log to the average, negates it and then uses
    the result as the real component in the frequency domain and
    combines that with a black imaginary component to transform
    it back to the spatial domain using +fft

See the script for actual code details.