Photographs of the real world are much more difficult to convert to sketches. There are several problems to be overcome.
Drawing the lines can be done by color mapping, as you suggested in your question, but this is difficult for photographs where shadows and angles cause surfaces to have many different colors. Skin has an especially rich set of colors.
A better method is to use edge detection, which looks for sharp transitions from one color to another. Edge detection still has troubles with dark, sharp shadows, such as those caused by a point source of light.
Once the edges have been detected, a threshhold function converts the various edge intensities to just black and white. Despeckling may also help here.
Here is a simple sequence of ImageMagick commands that make a line drawing from a photo.
Blur 90
Detect Edges 99.9
Threshhold 128
Negate
These are Image Magick commands with parameters, which I use from the menubar of the 'display' command, which is the interactive image manipulator that comes with Image Magick. The same commands should be available through the perl API.
If you have large photographs, you might try this sequence:
Blur 75
View half size
View half size
Enhance brightness 20
Greyscale
Spiff
Spiff
Spiff
Save as gif
Despecle
The spiff command enhances contrast. I use it three or four times in a row. For some unkown reason I seemed to need to save as a gif file to get the despecle command to work. This sequence creates a greyscale sketch.
Once you have your sketches, save them as a png. I found that png files are much smaller than both jpg and gif for this type of image.
I don't have perl code for these commands but it shouldn't be too difficult to write. I have used ImageMagick with perl before and didn't have any trouble with it, mostly because of the first tutorial provided by merlyn, which is referenced above.
If you want really nice, artistic sketches you have to be prepared to do some hand editing of the final result. Look at the sketches by an artist that you like. You will see that the work has a unique style associated with the artist. This style is difficult to capture in a simple algorithm. But not so difficult that I won't stop trying.
It should work perfectly the first time! - toma
In reply to Re: Image Sketch Convertion
by toma
in thread Image Sketch Convertion
by Everyone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |