Reputation: 37464
Using this image as reference:
How can I use to PHP and given an original image, output an outline version such as the ones below? I'll probably be using GD.
The best image that I can akin my requirement to is the one of Christopher Walken below. 1st column, 3rd down.
Upvotes: 1
Views: 2312
Reputation: 3527
Jaguar Library supports more than 30 Edge Detection Type Including Sobel
you can do what you want easily see Edge Detection
Upvotes: 2
Reputation: 4103
Blender's comment is important: different types of processing are required depending on the type of "cartoon" image that you want. It may not be feasible to automatically determine what type of image processing is required.
You might save yourself a lot of hassle by implementing 3 or 4 different image processing techniques, run all the techniques on each image, and then allow a user to choose the processed image that looks best.
Some processing techniques include the following:
If your image looks most like the Christopher Walken sample, then some form of binarization should work. To tinker with this, use the "Posterize" filter in Photoshop or GIMP. Binarization is an extreme case of posterization, with all colors (or in "grayscale" images, all brightnesses) squeezed down to just two: pure black and pure white. Choosing the right threshold automatically can be tricky, so it could help to offer the user a means to adjust the threshold.
You'll probably find that a simple binarization won't work as well as you'd like, but I'd suggest getting that code working first, identify its weaknesses, and then tinker further.
To learn more about thresholding, binarization, region labeling, etc., check out one of the most widely used textbooks on image processing:
Digital Image Processing by Gonzalez and Woods (3rd edition)
http://www.amazon.com/Digital-Image-Processing-Rafael-Gonzalez/dp/013168728X
(The retail price is high. Check addall.com to find a cheaper international edition, which could cost as little as $35.)
As long as you can access individual pixels, write individual pixels, work with matrices, etc., you can implement image processing. In GD you'll want to look into the built-in function to perform a convolution:
http://www.php.net/manual/en/function.imageconvolution.php
To use Sobel to find vertical lines, the 3x3 kernel would look like this:
|-1 0 1|
|-2 0 2|
|-1 0 1|
Rotate that kernel 90 degrees and you have a kernel to find horizontal lines. You can read more about the Sobel kernel at Wikipedia:
http://en.wikipedia.org/wiki/Sobel_operator
Upvotes: 1