G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
GREYC CNRS ENSICAEN UNICAEN

A Full-Featured Open-Source Framework for Image Processing



Latest stable version: 3.3.5        Current pre-release: 3.3.6 (2024/04/19)

Tutorial

Variations on a Theme
We won't give you blow-by-blow walk throughs in the following five variation as most of the steps are the same as what you have already seen in the previous receipe. Also, we've fetched Marek Ślusarczyk's lovely street scene into a local file called "street.png," just to cut the verbiage.

Variation One: Blur Horizontally.
Same graduated blur, but we want the direction to be left-to-right, not up-and-down.

gmic                                 \
   -input street.png                 \
   -input 100%,100%,1,1,'h-y'        \
   -normalize[-1] 0,1                \
   '(0^1^0)'                         \
   -resize[-1] [-3],[-3],[-1],[-1],1 \
   -split[-1] c                      \
   -append[-4,-3] c                  \
   -append[-2,-1] c                  \
   -eigen2tensor[-2,-1]              \
   -repeat 3                         \
      -smooth[-2] [-1],50            \
   -done                             \
   -rm[-1]                           \
tensorTensorsHere‘s the Big Change: we made Cosine constant one and Sine constant zero, instead of the other way around. Recall that the sine of 90° is one, and its cosine is zero. 90° points from top to bottom. Or if you want, bottom to top. With that we blurred in a vertical orientation. Here, cosine is one and sine is zero, which corresponds to 0° and we blurred in a horizontal direction.
hblurHorizontal BlurDo you see an emerging pattern? You betcha.

hblur
Kleine_Houtstraat: Horizontal blur storm settling in.

Variation Two: Blur in Any Direction.
Same graduated blur, but we want to choose any direction.

gmic angle=38.629                               \
-input street.png                               \
100%,100%,1,1,'h-y'                             \
-normalize[-1] 0,1                              \
'(0^{cos(pi*$angle/180)}^{sin(pi*$angle/180)})' \
-resize[-1] [-3],[-3],[-1],[-1],1               \
-split[-1] c                                    \
-append[-4,-3] c                                \
-append[-2,-1] c                                \
-eigen2tensor[-2,-1]                            \
-repeat 3                                       \
-smooth[-2] [-1],50                             \
-done                                           \
-rm[-1]                                         \
tensorTensorsG'MIC lets us declare variables (angle=38.629) and reference the values later: $angle. The $ signet tells G'MIC to look up the value of angle and substitute the expression with its value. That's exactly what we did later in the expression pi*$angle/180. That expression converts degrees into radians, as there happens to be one pi’s worth of radians for every one hundred eighty degrees and radian measure is what G'MIC expects.
hblur   Any Angle BlurIn the Greater Scheme Of Things, we're now setting Cosine and Sine to the angle by which we want to blur. Play with this yourself. Go put bunches of different angles in there.

ablur
Kleine_Houtstraat: Now a blur storm at any angle settling in.

Variation Three:  Blur From Bottom To Top
We want to do everything we've learned up to now, but vary the blur in the opposite direction.

gmic angle=32.754                               \
-input street.png                               \
-input 100%,100%,1,1,'y'                        \
-normalize[-1] 0,1                              \
'(0^{cos(pi*$angle/180)}^{sin(pi*$angle/180)})' \
-resize[-1] [-3],[-3],[-1],[-1],1               \
-split[-1] c                                    \
-append[-4,-3] c                                \
-append[-2,-1] c                                \
-eigen2tensor[-2,-1]                            \
-repeat 3                                       \
   -smooth[-2] [-1],50                          \
-done                                           \
-rm[-1]                                         \
tensorTensorsNo big deal blurring backwards. We changed the angle just for variation, giving you an example of how it's done, and we changed the ramp formula from h-y to y so that the ramp runs from zero to one instead of the other way around. In case you've missed it, you should spend some time with our Ramp Recipes.
hblurBottom Up BlurEvery gray scale ramp you have there can be used here. You can make a bazillion ramps and never repeat yourself. Now think of all the different ways you can make a ramp: Every single way can make a blur! Open road off to far horizons; we've hardly even taken the first steps. And yet there's more.

ablur
Kleine_Houtstraat: Now a blur storm emerging from the ground.

Variation Four: Blur With Any Ramp Orientation
Really. We don't have to go straight up and down all the time, do we?

gmic ang1=7.438 ang2=17.513                     \
-input street.png                               \
-input 100%,100%,1,1,'x*cos(pi*$ang1/180)+y*sin(pi*$ang1/180)' \
-normalize[-1] 0,1                              \
'(0^{cos(pi*$ang2/180)}^{sin(pi*$ang2/180)})'   \
-resize[-1] [-3],[-3],[-1],[-1],1               \
-split[-1] c                                    \
-append[-4,-3] c                                \
-append[-2,-1] c                                \
-eigen2tensor[-2,-1]                            \
-repeat 3                                       \
   -smooth[-2] [-1],50                          \
-done                                           \
-rm[-1]                                         \
tensorTensorsThe Big Thing here is the introduction of another variable and a formula which lets us run a ramp at any angle, which is something you have may have noticed if you went through the Ramp Recipes.
hblurMulti Angle BlurSo rather than run a ramp from top to bottom, or left to right, we run it at an angle of 7.48°, which is almost a horizontal ramp at a slight tilt. We introduced another angle variable just so that we could set the blur direction independently of the ramp direction.

ablur
Kleine_Houtstraat: And a blur storm coming in with the wind.

Variation Five: Introducing EigenTwo
You may have noticed that we haven't done anything with the EigenTwo image yet. It has been zero all the while. So what happens when we give that knob a twirl?

gmic                                            \
-input street.png                               \
-input 100%,100%,1,1,'h-y'                      \
-input 100%,100%,1,1,'y'                        \
-normalize[-2,-1] 0,1                           \
'(0^1)'                                         \
-resize[-1] [-4],[-4],[-1],[-1],1               \
-split[-1] c                                    \
-append[-4,-3] c                                \
-append[-2,-1] c                                \
-eigen2tensor[-2,-1]                            \
-repeat 3                                       \
   -smooth[-2] [-1],50                          \
-done                                           \
-rm[-1]                                         \
tensorTensorsWuff.
OK, a minor bit. We changed the image reference to -4 because we separated out the EigenTwo image from the one-pixel proto-image, making our image list longer by one. We then set up EigenTwo as a ramp running from zero to one, with EigenOne running from one to zero. We also put the business of running things at angles to one side to make the effect straightforward.
hblurEigen 1+2But what exactly is the effect?
It seems that we are ramping from a horizontal blur on the bottom to a vertical blur on the top, with a kind of neutral blurring in the middle.
Well, it is time to put the G'MIC toy to one side because we now have some Explaining to do.
See you on the next page.

ablur
Kleine_Houtstraat: And a three phase blur storm.


< Graduated BlursEigenvalues and Eigenvectors >
G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing

G'MIC is an open-source software distributed under the CeCILL free software licenses (LGPL-like and/or
GPL-compatible). Copyrights (C) Since July 2008, David Tschumperlé - GREYC UMR CNRS 6072, Image Team.