Skip to content

sunsided/opencv-cartoon-effect

Repository files navigation

Faux cartoon effect with OpenCV

Common tutorials around the web suggest that cartoon filters can be easily done by using median blurring, adaptive thresholding and edge detection. While this works, it achieves sub-par results almost certainly.

This approach replaces median blurring with anisotropic diffusion and uses edge dilation for more natural looking "strokes", as well as pyramid mean shift filtering for color reduction to achieve a more comic-like effect.

Cartoonified Grumpy Cat

This, of course, also only works with proper tuning of the parameters.

Here's the input image and the produced result for comparison. An alternative print-like faux-CMYK half-toning step was added using the rotated-grid crate; to play around with that, simply run the code with --features=halftone.

Input Output Halftoned

YMMV. 🐱