G'MIC Tutorial Fragments

gtutor_tileit has been updated in preparation for an upcoming cookbook article on tiling surfaces, primarily a math expression oriented recipe. Commit 05a01d18575c has the current script. Sun May 16 14:57:19 2021 UTC. It will work its way to the server shortly for people with current gmic cli. No gimp/Krita/8bf plug in yet. Cookbook article first. Commit notes:

modified:   include/garry_osgood.gmic

gtutor_tileit:
1. Removed provisional coloring. Mosaics read color and luminosity from selected images
   See ccount. Parameters basec and offsc have been removed.
2. Generate tilings with or without light/shadow rendering. Use fcolor switch.
   Defaults to False: render light/shadow on tiles.
3. Set tile size relative to image size. relative size 1.0 → 2.5% of the image diagonal.
4. Bug: lightangle not being used. Fixed. Set light angle from -180° to 180° inclusive.

gtutor_tileit help:
Generate a mosaic from an image. Works best with line art cartoons with flat color.
disrupt=5      Rotates, scales and displaces tiles. Suggest 0-10.
tsize=1.0      Tile size relative to image. 1.0 → tile diagonal is 2.5% of the image diagonal.
spread=1.5     Increasing promotes dropped tiles, gaps at junctions and runs. Suggest 0-3.
soft=0.5       Soften and dull shadows and highlights. Suggest 0-5.
fillholes=1    True:  Fill gaps and holes. No alpha channel.
               False: Leave gaps and holes. Image has alpha channel.
lightangle=45° Degrees: -180° – 180°. Lighting angle.
               45°: Light appears to stream from viewer's upper left.
ccount=4       Set number of dominant colors, taken from those most frequently occurring in source.
fcolor=0       True:  Flat color tiling without lighting and shading.
               False: Do tile lighting and shading.

Play files:

  1. ampersand_bluegold.svg. Continues my ongoing obsession(s) with the Goudy 1911 ampersand.
    ampersand_bluegold
  2. pompeiimask.svg. Loosely based on theatre mask mosaics seen in some villas in the Roman city of Pompeii.
    pompeiimask

Some results:

  1. Defaults
    pompeiimask_tiled
    Disruption: 5. Tile size: 1.0. Tile spread: 1.5. Highlight softening: 0.5. Holes: filling. Light angle: 45° Color count: 4 and shaded color.

  2. Smaller tiling and more colors
    pompeiimask_tinytiles
    Disruption: 0.25. Tile size: 0.25. Tile spread: 0.75. Highlight softening: 8. Holes: leaving. Light angle: 90° Color count: 16 and shaded color.

  3. Increasing disruption and shrinking tile size, also blurring to introduce intermediary color tiles. Flat, unshaded color (Light angle, soft: accepted but ignored).
    amp_flatnoisytiles
    Disruption: 5. Tile size: 0.25. Tile spread: 0.5. Highlight softening: 8. Holes: leaving. Light angle: 135° Color count: 32 and unshaded color.

  4. Setting spread to a high value creates beaded effect. Consider compositing such beaded results with other tiled images of the same source, but made with different settings.
    amp_widespread
    Disruption: 0.125. Tile size: 0.25. Tile spread: 2. Highlight softening: 0. Holes: leaving. Light angle: -75° Color count: 32 and shaded color.

gtutor_tileit: 05a01d18575c Sun May 16 14:57:19 2021 UTC

“”"
#@cli gtutor_tileit : 0<=_disrupt<=10,0.05<_tsize,0.25<=_spread,0<=_soft,_fillholes:True,-180<=_lightangle<=180,2<=_ccount<=32,_fcolor:False
#@cli : Generate a mosaic from an image. Works best with line art cartoons with flat color.
#@cli : disrupt=5 Rotates, scales and displaces tiles. Suggest 0-10.
#@cli : tsize=1.0 Tile size relative to image. 1.0 → tile diagonal is 2.5% of the image diagonal.
#@cli : spread=1.5 Increasing promotes dropped tiles, gaps at junctions and runs. Suggest 0-3.
#@cli : soft=0.5 Soften and dull shadows and highlights. Suggest 0-5.
#@cli : fillholes=1 True: Fill gaps and holes. No alpha channel.
#@cli : False: Leave gaps and holes. Image has alpha channel.
#@cli : lightangle=45° Degrees: -180° – 180°. Lighting angle.
#@cli : 45°: Light appears to stream from viewer’s upper left.
#@cli : ccount=4 Set number of dominant colors, taken from those most frequently occuring in source.
#@cli : fcolor=0 True: Flat color tiling without lighting and shading.
#@cli : False: Do tile lighting and shading.
gtutor_tileit : -check “${1=5}>=0 && 1<=10 && {2=1.0}>=0.05 && {3=1.5}>=0.25 && {4=0.5}>=0 && isbool({5=1}) && {6=45}>=-180 && {6}<=180 && {7=4}>=2 && {7}<=32 && isbool({8=0})”
-echo[^-1] "Applying faux tiling to selected images. Disruption: “{1}". Tile size: "{2}”. Tile spread: “{3}". Highlight softening: "{4}”. Holes: "${arg\ 1+!5,filling,leaving}". Light angle: "{6}“° Color count: “{7}" and "{arg\ 1+!$8,unshaded,shaded}” color.”

Parameters

disrupt=$1
tsize=$20.025sqrt(w^2+h^2)
spread=$3
soft=$4
fillholes=$5
lightangle=$6
ccount=$7
fcolor=$8

-repeat ! -local[>]
# Color quantization + black
-remove_opacity.
+colormap. ${ccount},1,2
-index… .,0,1
-round 1
1
-append[-2,-1] x
-name. pallette
-move[pallette] 0
-name. qcolor
+luminance[qcolor]
-name. qlumin
-normalize[qlumin] 0.6,1

  # Outline qcolor
  -input 100%,100%,1,1,'I(#-2,x,y)==I(#-3,0,0)?1:0'
  +deriche. 1,1,x
  -deriche.. 1,1,y
  -sqr[-2,-1]
  -add[-2,-1]
  -fill. 'i>={iM/3.0}?1:0'
  -name[-1] outline

  # Cost: perturbs distance to outline measure, a basis of tile irregularity
  -input 100%,100%,1,1
  -name[-1] cost
  -plasma[cost] 4,4,{$disrupt}
  -normalize[cost] 0,{$disrupt/4.0}

  # Distance to outline + distance perturbation
  +distance[outline] 1,[cost],1
  -name. distvar
  +distance[outline] 1
  +add[-1,-2]
  -remove[-3,-2]

  # True distance: basis for marking off distance by tile height
  [-1]
  -name[-1] truedistance

  # Orient: source of tile rotation
  -name[-2] orienter

  # Make Warper: distorts tiles
  -gradient[cost] xy
  -append[-4,-3] c
  -blur[-3] 1,1,1
  -normalize... {-1.5*$disrupt},{1.5*$disrupt}
  -name... warper

  #  Measure out and scribe tile center-to-center lines
  -round[truedistance] {$spread*$tsize}
  +deriche[truedistance] 1,1,x
  -deriche[truedistance] 1,1,y
  -sqr[-2,-1]
  -add[-2,-1]
  -fill. 'i>{iM/4.5}?1:0'

  # Compute orientation field
  -gradient[orienter] xy
  -append[-3,-2] c
  -orientation[orienter]

  # Plotting field:
  [-1],[-1],1,4,'[-1,-1,-1,0]'
  -name. plottingfield

  # Draw tiles on a plotting field:
  # (1) xfrm: encodes tile translations and rotations
  # for tile corner points. (2) tl, tr, bl, br:
  # tile corners, expressed in homogeneous
  # coordinates.
  -fill[plottingfield] ">if(
                             0<i#-2 && I#-1==[-1,-1,-1,0],
                             xfrm=eye(3);
                             xfrm[0]=I#-3[1];
                             xfrm[1]=I#-3[0];
                             xfrm[2]=x;
                             xfrm[3]=-I#-3[0];
                             xfrm[4]=I#-3[1];
                             xfrm[5]=y;
                             tl=mul(xfrm,[-"$tsize",-"$tsize"/2.0,1],1);
                             tr=mul(xfrm,[ "$tsize",-"$tsize"/2.0,1],1);
                             bl=mul(xfrm,[-"$tsize", "$tsize"/2.0,1],1);
                             br=mul(xfrm,[ "$tsize", "$tsize"/2.0,1],1);
                             polygon(#-1,5,
                                     [tl[0],tl[1]],
                                     [tr[0],tr[1]],
                                     [br[0],br[1]],
                                     [bl[0],bl[1]],
                                     [tl[0],tl[1]],
                                     1,[[I#-7]*i#-6,255]);
                             polygon(#-1,-5,
                                     [tl[0],tl[1]],
                                     [tr[0],tr[1]],
                                     [br[0],br[1]],
                                     [bl[0],bl[1]],
                                     [tl[0],tl[1]],
                                     1,0xffffffff,[0,0,0,255])
                           );I"

  -cut[plottingfield] 0,255

  # Make isovalue targets for lighting height map
  100%,100%,1,1,'I#-1==[0,0,0,255]?1:0'
  -name. heightmap

  # Distort artwork
  -warp[plottingfield,heightmap] [warper],1,2,2

  # Clean up
  -remove[-3--6]
  -split_opacity[plottingfield]
  -index[plottingfield] [pallette],0,1
  -remove[pallette]
  -fill.. 'i>=127?255:0'
  -fill. 'i>0.05?1:0'
  -fill. 'i#-2==0?0:i'
     
  -if $fcolor # Do light and shade?
     -if $fillholes
        # Fill holes in the plotting field
        -fill[plottingfield] 'i#-2==0?I#-5*i#-4:I'
    -remove[-2]
 -else
    -append[-3,-2] c
 -fi
     -keep[plottingfield]
  -else
     # Distance from edges: proxy for
     # tile height. Shape height with
     # power function
     -distance[heightmap] 1
     -normalize[heightmap] 0,1
     -pow. 0.25
     -blur. 0.875,1,1
     -normalize[heightmap] 0,1

     -if {$fillholes==0}
        # Poke holes in the height map
        -fill[heightmap] 'i#-2==0?0:i'
     -else
        # Fill holes in the plotting field
        -fill[plottingfield] 'i#-2==0?I#-5*i#-4:I'
     -fi
     -remove[qcolor,qlumin]

     # Cheap Fingerpaint Lighting
     # Derive shadow, hightlight, color

     -normalize[plottingfield] 0,1

     # Light
     +gradient[heightmap] xy
     -append[-2,-1] c
     ({cos($lightangle*pi/180)}^{sin($lightangle*pi/180)})
     -resize. [-2],[-2],[-1],[-1],1
     +mul[-2,-1]
     -compose_channels. add
     -name. light
     -cut. {ia},{iM}
     -normalize. 0,1
     -pow. 0.5
     if $soft>0
        -blur. {$soft},1,1
     fi

     # Shadow
     -mul.. -1
     -mul[-3,-2]
     -compose_channels.. add
     -name.. shadow
     -cut.. {ia#-2},{iM#-2}
     -normalize.. 0,1
     -oneminus..
     -pow.. 2

     # Composite
     -mul[plottingfield,shadow]
     -mul[light] '{iM#0}'
     -add[plottingfield,light]
     -normalize[plottingfield] 0,255
     -if {$fillholes==0}
        -append[-3,-2] c
     -else
        -remove..
     -fi
     -keep[0]
  -fi # else doing light and shade

-endlocal
-done

“”"

Off to work on the cookbook recipe. Everybody have fun.

3 Likes