G’mic is a massive collection of image processing filters combined to a one easy to use gui and cli program that can be installed on gimp, krita etc … or used on the terminal, it’s so big even tho i already made a markdown file specific for showing it with many examples i barely scratched the surface of what it does and i’m going to showcase one of it’s filters here
for the basics of how to use the G’mic look here , now that you are somewhat familiar with this program lets do our thing
stylize is a cool filter for applying style transfer to our images, see here for a deep dive of the filter documented by G’mic, stylize is the most easy to use and un-complicated implementation of style transfer i have seen that runs locally on your computer without the need for internet or installing extra programs like python, lua or others
note: images that are linked in this markdown file are compressed to make loading the page faster, for the uncompressed versions go to the examples folder
everything is downloaded from a royalty free image website here and here, there is also some royalty free stock footage from youtube
basic | advanced |
---|---|
the default options in the gui translates to this command in the cli by clicking on the copy command icon on the top right side of the gui
fx_stylize 0,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0
add a gmic behind the command, specify your input image and output image, styles has a few images embedded into it if you don’t want to set an style image
gmic input.jpg fx_stylize 2,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o output.jpg
the 2 after fx_stylize tells gmic to use the 3rd option in the first gui entry which is the first embedded image style, by default 0 is used which uses the first image as our style so if we want to specify our own style we set that number to 0 and insert 2 images to gmic
gmic style.jpg input.jpg fx_stylize 0,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o output.jpg
we’ll start we some pre-embedded images as styles, this is easiest way to use the filter
gmic earth.jpg fx_stylize 32,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o earth_gogh+.jpg
input | style (Picasso: Seated Woman) | output |
---|---|---|
gmic statue.jpg fx_stylize 25,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o statue_mondrian+.jpg
input | style (Mondrian: Gray Tree) | output |
---|---|---|
gmic tree.jpg lighthouse.jpg fx_stylize 0,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o Light_tree.jpg ; rm *000000.jpg
this command outputs two images, Light_tree_000000.jpg
which is the same as our input image and Light_tree_000001.jpg
which is what we actually want so for further commands we add a remove command at the end of our command to remove this un-needed file like this ; rm *000000.jpg
the ;
add the remove command to our gmic command to make it a one liner
input | style | output |
---|---|---|
by default stylize sets your style image to 75% of it’s size and uses it to re-create the input image, you can set this operation to none or make the resizing smaller or bigger depending on your style image, the default value is a good start point and might be fine for your case but we’ll still show the differences here
changing style scale is done by changing the second number we pass to fx_stylize filter, it starts at 0 and ends at 10
input | style |
---|---|
10% scale (1) | 50% scale (4) |
150% scale (7) | 300% scale (10) |
smoothness decides how much styles uses the style image to recreate the input image, the higher the smoothness the less the style image is used and the output image effected
input | style |
---|---|
smoothness 0 | smoothness 5 |
by default stylize only takes 20% (1 out 5) of gradients into the effect, this part of the filter works in tandem with the smoothness option but won’t mix them here because we want to showcase it on it’s own
input | style |
---|---|
gradients 0 | gradients 5 |
there is simply too many options to go over, i’m not sure how effective they are and how much they might show up in result outputs as i didn’t have the time to test them, but i’ll make sure to include them if they caught my attention
making a animated gif with stylize is just as easy as still images, we just need a for
loop for batch processing, if we don’t have a image sequence of your gif file you can make one like this
ffmpeg -i my.gif -vsync 0 S-%4d.jpg
the above command pads 4 zeros to our images after S-
, each gif file is limited to 500 frames but we add an extra 0 at the beginning to make life easier for our for loop and the conversion of our stylized sequence to gif again
now for converting our newly made image sequence
for i in S-0*.jpg ; do gmic crochet.jpg $i fx_stylize 0,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o G-$i.jpg ; rm *000000.jpg ; done
now make the animated gif
cat G-*.jpg | ffmpeg -framerate 30 -f image2pipe -i - -preset veryslow crochet_face.gif
input | output |
---|---|
for the style image go to the gif folder inside examples, these gifs were significantly compressed using gifsicle to make their size way smaller and are not representative of the actual result quality
lets apply what we learned to a video, i have made a example of how to download a free video, make image sequence, apply filter and mux it back here
for i in *.jpg ; do gmic neon.jpg $i fx_stylize 0,5,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o G-$i.jpg ; rm *000000.jpg ; done
as you can see the process is similar to gif making, we just want to make a video instead, videos have the advantage of applying a uniform compression to each frame and produce amazing quality images with a really small output size
cat G-*.jpg | ffmpeg -framerate 30 -f image2pipe -i - -preset veryslow guitar-neon.mp4
here is another example at half speed
we’ve been trying to re-create the input images as best as we can and get a clear result, lets change all of that and destroy the input
the easiest way you can go about this is using a frame out of an image sequence as the style image
for i in *.jpg ; do gmic 0468.jpg $i fx_stylize 0,6,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o G-$i.jpg ; rm *000000.jpg ; done
using a glitched image as style
use a pixelated or a very small image as style
use a blank noise image as style
use a dithered gradient as style
use G’mic’s own pixel sort filter for style
use G’mic’s own charcoal filter for style
it’s kind of hard to know how an image might look without converting it first, when in doubt, stylize them all!
for i in *.jpg ; do gmic $i statue_of_liberty.jpg fx_stylize 0,6,0,0,0.5,2,3,0.5,0.1,3,3,0,0.7,1,0,1,0,5,5,7,1,30,10,2,1.85,0 -o G-$i.jpg ; rm *000000.jpg ; done