Skip to content

Instantly share code, notes, and snippets.

@davide-romanini
Created February 25, 2016 12:35
Show Gist options
  • Save davide-romanini/1c167144158e3248f450 to your computer and use it in GitHub Desktop.
Save davide-romanini/1c167144158e3248f450 to your computer and use it in GitHub Desktop.
Custom command for (vintage) scanned comics enhance. Requires gmic 1.6.9
#@gmic comic_enhance : unsharp_level=0 bg=255,255,255 black=0,0,0 white=255,255,255 noise_rm=3,3,1 bilateral=10,10,2 erode=0 desaturate=0
#@gmic : Applies a bunch of filters to better render scanned comics
#@gmic : - unsharp (default 0): enhance details, useful for blurry scans
#@gmic : - bg: background color to remove. This color is blended in divisor mode, useful for vintage comics
#@gmic : - black: black point used to adjust color curves
#@gmic : - white: white point used to adjust color curves
#@gmic : - noise_rm (3,3,1): uses -iain_iains_nr filter to smooth out colors. slow but effective.
#@gmic : - bilateral (10,10,2): uses -gimp_bilateral as a second smoothing step
#@gmic : - erode: uses -gimp_morpho with circular kernel and minimal size of 2 to "engrave" strokes
#@gmic : - desaturate: uses the -desaturate_luminosity filter for grayscale pages
comic_enhance:
-skip ${1=0},${2=255},${3=255},${4=255},${5=0},${6=0},${7=0},${8=255},${9=255},${10=255},${11=3},${12=3},${13=1},${14=10},${15=10},${16=2},${17=0},${18=0}
-v -
unsharp=$1
background=${2-4}
black_R=$5
black_G=$6
black_B=$7
white_R=$8
white_G=$9
white_B=$10
smooth1=${11-13}
smooth2=${14-16}
erode=$17
desaturate=$18
-if {$unsharp>0}
-v + -e "Unsharping level"${unsharp} -v -
-_gimp_unsharp 0,1.25,30,$unsharp,0,1,1,1,0
-endif
-v + -e "Removing background "${background} -v -
--fill_color $background -blend divide
-v + -e "Applying color levels" -v -
-apply_channels "-apply_curve 1,"${black_R}",0,"${white_R}",255",rgba_r
-apply_channels "-apply_curve 1,"${black_G}",0,"${white_G}",255",rgba_g
-apply_channels "-apply_curve 1,"${black_B}",0,"${white_B}",255",rgba_b
-if {$11>0&&$12>0&&$13>0}
-v + -e "Smoothing first pass.. be patient" -v -
-iain_iains_nr $smooth1,0,-32000,0,1,0,0,0,1.35,0,0
-endif
-if {$14>0&&$15>0&&$16>0}
-v + -e "Smoothing second pass" -v -
-gimp_bilateral $smooth2,0,0,24,0
-endif
-if {$erode==1}
-v + -e "Eroding" -v -
-gimp_morpho 0,2,0,2,0,0,0
-endif
-if {$desaturate==1}
-v + -e "Desaturation" -v -
-desaturate_luminosity
-endif
# Gimp luminosity desaturation formula
# https://docs.gimp.org/2.6/en/gimp-tool-desaturate.html
#@gmic desaturate_luminosity
#@gmic : Apply the same math of gimp Desaturate -> Luminosity tool
#@gmic : see https://docs.gimp.org/2.6/en/gimp-tool-desaturate.html
desaturate_luminosity:
-fill '0.21*R+0.72*G+0.07*B' -to_gray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment