Photo to cartoon script

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?".
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Photo to cartoon script

Post by Bonzo »

I was trying to create an "Andy Warhol" type effect last year but did not finish it. Basicly I was selecting a colour, setting a fuzz and replacing that range with one colour using a mask.
ImageImage
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: Photo to cartoon script

Post by dognose »

Bonzo, I like your example. Do you remember the exact code you were using? Were you using manual coloring, or did you have a good way to map "toonish" colors?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Photo to cartoon script

Post by Bonzo »

Below is the code I used; it is a mess as I didn't take it any further - I was also working with a face hence the strange names/references. It is creating simple coloured areas from a colour range and changing the rest of the image to transparent. These coloured areas are then overlapped to create the final image.
If you try it with the image I posted you will see the different masks; this was a step on from this example http://www.rubblewebs.co.uk/imagemagick ... =green.jpg

I also wrote some other code to pick out the colours but again I didn't finish it:
http://www.rubblewebs.co.uk./imagemagic ... s/imap.php

Code: Select all

<?php
// Resized the original image
exec("convert butterfly_sunflower_1.jpg -resize 400x300! reduced_colours1.jpg");

exec("convert reduced_colours1.jpg -matte ( +clone -fuzz 20% -transparent rgb(90,135,202) ) -compose DstOut -composite hat_mask.png"); 

exec("composite -compose Dst_in hat_mask.png -size 400x300 xc:blue green_hat.gif"); 

// Change the black to transparent
exec("convert green_hat.gif -transparent black black_trans.png");

exec("convert reduced_colours1.jpg -matte ( +clone -fuzz 20% -transparent rgb(196,144,0) ) -compose DstOut -composite lips_mask.png"); 

exec("composite -compose Dst_in lips_mask.png -size 400x300 xc:yellow red_lips.gif"); 

// Change the black to transparent
exec("convert red_lips.gif -transparent black red_trans.png");

exec("convert reduced_colours1.jpg -fuzz 12% -transparent rgb(68.81,27) face_mask.png"); 

exec("composite -compose DstOut face_mask.png -size 400x300 xc:green pink_face.png");

// Change the black to transparent
exec("convert pink_face.png -transparent black pink_trans.png");

// Composite the images
exec("convert pink_trans.png black_trans.png -composite red_trans.png -composite final.jpg"); 
?>

<img src="hat_mask.png">
<img src="green_hat.gif">
<img src="black_trans.png">
<img src="lips_mask.png">
<img src="red_lips.gif">
<img src="red_trans.png">
<img src="face_mask.png">
<img src="pink_face.png">
<img src="pink_trans.png">
<img src="final.jpg">
<img src="reduced_colours1.jpg">

johnymac

Re: Photo to cartoon script

Post by johnymac »

Has anyone done any more on this? I'm trying to create one but failing badly at knowing what to do.

The best I have so far is..

Sorry about slow site btw..

http://crm.primaryt.co.uk/ppix/test12.php & http://crm.primaryt.co.uk/ppix/test10.php
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photo to cartoon script

Post by anthony »

metaph wrote:Has anyone given any thought as to how to cartoonize a digital photo using ImageMagick? I'd like to script a bunch of these.

I have been playing with blending together reducing the colors, and using paint, charcoal and (optionally) the sketch filter. I tried using some colormaps and posterize but didn't like the results as much.
It can be done, and some methods are on the web. one method called rotoscope, as been used to generate a flat cartoon like effect from film in the movie of Phillip K Dick's novel 'Scanner Darkly'.

Typically many of the area segmentation methods used for real images can also be used for cartoon like effects.

Please search and explore and if you find something let us know and people of the forum may be ablet to help further.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
johnymac

Re: Photo to cartoon script

Post by johnymac »

I was wondering if this could be done with imagemagick, not a gui. I will check out gmic though
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photo to cartoon script

Post by anthony »

Forget gmic. the download TAR does not see to contain any code, and seems to be a wrapper around some other library they have not even bothered to mention in the INSTALL, README, Downloads, or on the page itself!!!!!

Of course the rest of the site is in French, which makes it doubly hard!

I was interesting in looking at some of their operators, and even the 'open-source' interpretor.
I can find neither!

I have no idea how they expect anyone else to do it if an experienced programmer fails!!!


Fred, most of your references was a gimp search for the 'Andy Worhol' effect, which is not 'cartoonizing' an image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Photo to cartoon script

Post by fmw42 »

Anthony,

Bonzo mentioned Andy Warhol effect above and the first user was asking how to do it. So I did a google search and reported my results. I thought that was what the original user was ultimately getting at as he responded positively to Bonzo's reply.

I am sure there are many ways to "cartoon" an image. Just saying "cartoon" does not give anyone any idea what that means and he provided no visual results or references. Is there a standard technique for what "cartoon" means to most people?

One day I might try to make a script to do the Warhol effect in IM. But it seems to be very manually oriented on a picture by picture case and there seem to be numerous ways to do it by the variations discussed in the google search results.

Sorry about the G'MIC. But I have never tried it. I did contact the originator once, but did not get much help. The docs and examples seemed to be very impressive.

The original reference was on the IM site at
http://www.imagemagick.org/script/links.php

perhaps(???) it should be removed, if there is no code to install or it is not clear how to do it?
johnymac

Re: Photo to cartoon script

Post by johnymac »

haha Anthony, I got gmic going, it was a right mission. I guess I did okay eh ;)

Anyways, it doesn't change from the fact it sucks..

My definition of Cartoon is to have a few pixel border to emphasize lines of the face then to quantize (I think) the amount of colours..

BeFunky has a good example online but BeFunky as a company seem to fail.
johnymac

Re: Photo to cartoon script

Post by johnymac »

I blogged about how I accomplished it

http://www.mclear.co.uk/2009/06/how-to- ... -turn.html
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photo to cartoon script

Post by anthony »

What were your GMIC dependencies?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Photo to cartoon script

Post by fmw42 »

johnymac wrote:I blogged about how I accomplished it

http://www.mclear.co.uk/2009/06/how-to- ... -turn.html

Curious, but none of these look like what I would expect for a "cartoon". Are any of these what you really wanted? Is it more like what one sees from the cartoon example at BeFunky?

Can you post the same image with your attempts using IM? And any comments about what IM options seem to produce the closest to what you are looking for in a "cartoon".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Photo to cartoon script

Post by fmw42 »

Just playing around. I tried: 1) +dither -posterize 6 and 2) -quantize RGB +dither -colors 32. Here are the comparisons with the originals (ordered as original, posterize, colors versions):

Image

Image

Image


Image

Image

Image


Image

Image

Image


Image

Image

Image


Image

Image

Image

I think I slightly prefer the -colors 32 to the posterize 6.
Last edited by fmw42 on 2009-06-18T12:29:59-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Photo to cartoon script

Post by fmw42 »

johnymac wrote:Has anyone done any more on this? I'm trying to create one but failing badly at knowing what to do.

The best I have so far is..

Sorry about slow site btw..

http://crm.primaryt.co.uk/ppix/test12.php & http://crm.primaryt.co.uk/ppix/test10.php

Where is the original?
Post Reply