cartoonizer / vectorizer

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: cartoonizer / vectorizer

Post by snibgo »

Those images vary widely. I can't find a single command with fixed parameters that looks good on all of them. A command that looks good with some, but not all, is:

Code: Select all

convert in.jpg \
  \( -clone 0 -median 2 -colors 5 -median 2 -blur 3 \) \
  \( -clone 0 -colorspace Gray -median 8 -edge 2 \
    -negate -normalize -level 0x75% \
    -negate -alpha copy \
    -channel RGB -negate \
    -threshold 50% \) \
  -delete 0 ^
  -composite out.jpg
The various parameters (colors, edge, etc) should be varied according to the "complexity" of the image. For simple images, edge can be increased. For complex images, edge should be kept small, with increased colors.
snibgo's IM pages: im.snibgo.com
st3v3n

Re: cartoonizer / vectorizer

Post by st3v3n »

hmm, i tried... it doesnt end up - it takes too much of the shadows and color changes into the edges instead of using real edges...
i really wonder how befunky does it
st3v3n

Re: cartoonizer / vectorizer

Post by st3v3n »

http://i175.photobucket.com/albums/w154 ... c-cart.jpg

look at that - its done with g'mic and a cartoon filter... drives me nuts - i cant get that done... a simple cartoonish looking filter...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cartoonizer / vectorizer

Post by fmw42 »

nice result. so can you not use GMIC in batch form and get what you need done?
st3v3n

Re: cartoonizer / vectorizer

Post by st3v3n »

i tried to use g'mic...
i installed the .deb and tried to execute something in the commandline but that thing is so cryptic...
also it always wants to render a X11 display... i have no idea why it would want to do that...

right now it gives me this output:
# gmic in.jpg -blur 1 -cartoon -o result.jpg

[gmic]-0./ Start G'MIC instance.
[gmic]-0./ Input file 'in.jpg' at position [0] (1 image 398x299x1x3).
[gmic]-1./ Blur image [0], with standard deviation 1 and neumann borders.
[gmic]-1./ Apply cartoon effect on image [0], with smoothness -o, sharpening 200, threshold 15, thickness 0.25, color 1.5 and quantization 8.
[gmic] *** Error in ./cartoon/ *** Command 'blur' : Invalid argument '-o'.

-blur std_variation>=0[%],_borders

Blur selected images by quasi-gaussian recursive filter.

'borders' can be { 0=dirichlet | 1=neumann }.
st3v3n

Re: cartoonizer / vectorizer

Post by st3v3n »

also that result from flickr is from someone else.
who describes it as "used the Artistic-Cartoon filter with 50% overlay"...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cartoonizer / vectorizer

Post by fmw42 »

there is a gmic plugin for gimp. unfortunately not for Mac OSX PowerPC so I cannot try it. perhaps one could figure out what it is doing by playing with it. see http://gmic.sourceforge.net/gimp.shtml
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cartoonizer / vectorizer

Post by fmw42 »

playing around some:

original
Image


convert chloe_mod_100x150_100.png -selective-blur 0x3+10% -segment 1000x0.5 chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5.png
Image


convert chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5.png -edge 4 -colorspace gray -negate -threshold 1% chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5_gne4_t1.png
Image


convert chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5.png chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5_gne4_t1.png -compose multiply -composite chloe_mod_100x150_100_sb_0x3x10_seg_1000x0p5_comp_gne4_t1.png
Image


The edge image needs a lot more work.
st3v3n

Re: cartoonizer / vectorizer

Post by st3v3n »

i wonder how the cartoon filter from gmic works because it seperates the colors so well instead of just reducing colors dithered...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: cartoonizer / vectorizer

Post by snibgo »

GMIC won't run on my Windows 7 64-bit platform.

From the screenshots, I notice that GMIC has adjustable parameters. I wonder if one can find a set of parameters that will suit every image? I doubt it.

For fmw's Cloe shot: I suggest the edge is applied to the original (possibly median'ed first), rather than the segmented version.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cartoonizer / vectorizer

Post by fmw42 »

Here is another try

Image

convert chloe_mod_100x150_100.png -paint 6 chloe_mod_100x150_100_paint6.png
Image

convert chloe.png -colorspace gray chloeg.png
convert chloe.png -colorspace gray -negate chloegn.png
gradient chloegn.png miff: | convert - -negate chloegn_grad.png
gradient chloeg.png miff: | convert - -negate chloeg_gradn.png
convert chloegn_grad.png chloeg_gradn.png -evaluate-sequence min -threshold 50% cloeg_grad_t50.png
morphology -t open cloeg_grad_t50.png cloeg_grad_t50_open1.png
Image


convert chloe_mod_100x150_100_paint6.png cloeg_grad_t50_open1.png -compose multiply -composite chloe_mod_100x150_100_paint6_comp_grad_t50_open1.png
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: cartoonizer / vectorizer

Post by snibgo »

Image

"%IMG%convert" ^
chloe.png ^
( -clone 0 -colorspace Gray -median 6 ) ^
( -clone 1 -adaptive-blur 6 ) ^
( -clone 1 ^
-clone 2 ^
-compose minus -composite ^
-normalize ^
-level 50x100%% ^
-alpha copy -negate ) ^
( -clone 2 ^
-clone 1 ^
-compose minus -composite ^
-normalize ^
-level 50x100%% ^
-alpha copy ) ^
-delete 0-2 ^
-compose src-over -composite ^
chloeMedLines.png

"%IMG%convert" ^
chloe.png ^
( -clone 0 -colorspace Gray -median 15 ) ^
( -clone 1 -adaptive-blur 15 ) ^
( -clone 1 ^
-clone 2 ^
-compose minus -composite ^
-normalize ^
-level 50x100%% ^
-alpha copy -negate ) ^
( -clone 2 ^
-clone 1 ^
-compose minus -composite ^
-normalize ^
-level 50x100%% ^
-alpha copy ) ^
-delete 0-2 ^
-compose src-over -composite ^
chloeThickLines.png

"%IMG%convert" ^
chloeMedLines.png ^
chloeThickLines.png -composite ^
-channel Alpha -evaluate Multiply 0.5 ^
chloeLines.png

"%IMG%convert" ^
chloe.png ^
-median 3 -segment 1000x0.3 ^
chloeCol.png

"%IMG%convert" ^
chloeCol.png ^
chloeLines.png ^
-composite ^
chloeFinal.png

This is on Windows. %IMG% is my location of ImageMagick. The five commands could be squished into one.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cartoonizer / vectorizer

Post by fmw42 »

I think I have now two good ways to reduce the colors. The first is to use -color, BUT on each channel separately. This method is rather insensitive to the number of colors specified (between about 6 and 14). The second uses an fx expression, floor(u*$numcolors+0.5)/$numcolors, but applies it via -clut. This method gives nice variation in the results depending upon the number of colors. Both methods produce similar results for about 10 colors.

I have created a script, cartoon, on my web site below, with more examples. But here is one.

Image
tournevissette

Re: cartoonizer / vectorizer

Post by tournevissette »

st3v3n wrote:i tried to use g'mic...
i installed the .deb and tried to execute something in the commandline but that thing is so cryptic...
also it always wants to render a X11 display... i have no idea why it would want to do that...

right now it gives me this output:
# gmic in.jpg -blur 1 -cartoon -o result.jpg

[gmic]-0./ Start G'MIC instance.
[gmic]-0./ Input file 'in.jpg' at position [0] (1 image 398x299x1x3).
[gmic]-1./ Blur image [0], with standard deviation 1 and neumann borders.
[gmic]-1./ Apply cartoon effect on image [0], with smoothness -o, sharpening 200, threshold 15, thickness 0.25, color 1.5 and quantization 8.
[gmic] *** Error in ./cartoon/ *** Command 'blur' : Invalid argument '-o'.
The '-cartoon' needs an argument :

# gmic -h cartoon

-cartoon _smoothness,_sharpening,_threshold>=0,_thickness>=0,_color>=0,quantization>0

Apply cartoon effect on selected images.

If you want to skip putting arguments, just put ',' :

# gmic in.jpg -cartoon , -o out.jpg

Of course, if you specify a file output, then no X11 display are showing.
digitalorca

Re: cartoonizer / vectorizer

Post by digitalorca »

Fred - I tried your cartoon.sh script on 6.5.4-1.

Used all defaults:

cartoon.sh test.png result.png

This is the result:

convert: magick/cache-view.c:712: GetCacheViewVirtualPixels: Assertion `id < (long) cache_view->number_threads' failed.
./cartoon.sh: line 274: 5166 Aborted convert $tmpA1 $medianize1 -separate -colors $numcolors +dither -combine $smoothing $tmpA2
convert: unable to open image `./cartoon_2_5159.mpc': No such file or directory @ blob.c/OpenBlob/2476.
convert: missing an image filename `t.jpg' @ convert.c/ConvertImageCommand/2772.
Post Reply