-haar

Figure 1: A pyramid of smiley face differences

Performs a Discrete Wavelet Transform (DWT) analysis on the selected images by means of the Haar wavelet basis, producing a pyramid of differences at powers-of-two scales, with the one base image at the highest scale occupying the upper left corner of the image, (see example on the left), and the difference images, at decreasing scales (and larger size) radiating out in concentric ranks to the lower right. This pyramid constitutes a DWT analysis of the input image.

The base image can be as small as one pixel, though it will be larger if at least one dimension of the original image is not a power of two or the image is not square (see nb_scales, following).

-ihaar is the companion G'MIC DWT synthesis command, which recovers the original when given an analysis produced by -haar.

The format of the command is:

-haar nb_scales > 0

A Haar Command Example

#@gmic pixelate : _coarse>0,_details={ 0 | 1 }
#@gmic : Yet another pixelize. You can't have
#@gmic : enough of these.
#@gmic : coarse increases pixelization.
#@gmic : details puts saved details in
#@gmic : another image.
#@gmic : Default values: 'coarse=3' 'details=0'
#@gmic : $ image.jpg -pixelate 5
pixelate : -check "${1=3}>=0 && isbool(${2=0})"
-e[^-1] "Coalesce image$? into pixels at scale $1"
-verbose -
chk=2^$2
-repeat $!
-local[{$>*$chk}]
sc={round(log2(max(w,h)))}
ow={w}
oh={h}
dm={2^$sc}
-if {$sc<$1}
px={2^$sc}
-else
px={2^$1}
-endif
-if {$dm!=$ow||$dm!=$oh}
-resize[-1] {$dm},{$dm},[-1],[-1],0
-endif
-haar {$sc}
-input 100%,100%,100%,100%
-rectangle[-1] 0,0,{w/$px},{h/$px},1,1
-if $2
--negative[-1]
--mul[-3,-1]
-rm[-2]
-mv[-1] 0
-endif
-mul[-2,-1]
-ihaar {$sc}
-normalize 0,255
-crop 0,0,{$ow-1},{$oh-1}
-endl
-done
-verbose +

The G'MIC script on the left defines a command called '-pixelate.' Copy this into your local “~/.gmic” file (Unix-like OS) or /%APPDATA%/gmic (Windows).

When an image has been analyzed, it is susceptible to spectral editing. To “pixelate” an image this script makes a boolean mask that zeros-out difference images at or lower than the scale specified by coarse. With these removed from the pyramid, the subsequent synthesis will only be able to partially recover the image. The result appears pixelated due to the character of the Haar wavelet, a square function that transitions from 0 to 1, 1 to -1, then -1 to zero.

An optional flag, details=1, separates out the details into another image. This entails using an inverted version of the boolean mask that zeros out the scales the first one preserves, and retains the scales the first one removes.

In either case, -ihaar performs a synthesis on an edited pyramid stack and restores only subsets of the information originally contained in the input image.

See Wavelet Analysis and Synthesis in G'MIC in the Technical Notes section for the background on this command and its inverse, -ihaar.