How to cartoon-ify an image programmatically?

前端 未结 8 696
粉色の甜心
粉色の甜心 2020-11-28 17:37

My app works with photos and videos of people, which I want to cartoonify. So I need an algorithm to do it manually (we use c++/Qt for our product, which has image manipulat

相关标签:
8条回答
  • 2020-11-28 18:09

    If there's some set of parameters which achieve the desired effect in the GIMP's Cartoon filter (or some other combination of filters) it can be run in a batch processing mode.

    0 讨论(0)
  • 2020-11-28 18:11

    You might want to check out Freestyle, an open-source (Google Summer of Code, even) project to implement a non-photorealistic renderer for Blender. Here's an example of its output, in cartoon-mode:
    (source: sourceforge.net)

    0 讨论(0)
  • 2020-11-28 18:12

    Here's some algorithms to play with:

    • Median or repeated box blur filter to obtain cartoonish color palette
      • Edit: Bilateral filtering should suit your needs even better
    • Min filter (zeroth percentile) to enhance some types of edges
    • Color image segmentation using either small subcube or sphere in the RGB color cube
    • Generic edge enhancement on segmented image using edge detection such as Sobel kernels or 8-way edge tracing
    • Composit blurred/median-filtered image with enhanced edges

    These are fairly basic and all very easy to implement. Keep in mind that median and box blur filters can be implemented with linear time complexity w.r.t. the kernel radius.

    More edits:

    Once you get the idea of Huang's algorithm, implementing a box blur filter is a delicious piece of cake.

    Reading material:

    • Fast Median and Bilateral Filtering (get the PDF)
    • Median Filtering Constant time (get the PDF) Note: I have an implementation of this in C# using Mono/SIMD to accelerate histogram coalescence, however it only seems better than the O(r) algorithm when the diameter exceeds ~60 pixels due to the comparable number of add/sub instructions (the break-even point), a C++ implementation is probably much better suited to harness SIMD.

    Other reading materials include Gonzalez & Woods' Digital Image Processing (seems to be an older edition) for segmentation and edge tracing. 8-way edge tracing can be really hard to bend your head around (choosing between on-pixel or between-pixel edges and how to latch onto edges). I'd be happy to share some code, but the hundred-liners don't exactly fit smoothly in here.

    0 讨论(0)
  • 2020-11-28 18:12

    Not sure if this will help, but this tutorial for Photoshop suggests doing the following:

    1. Open your image in Photoshop
    2. Filter > Blur > Gaussian Blur. Set the radius at 3.0 or higher, to taste.
    3. Edit > Fade Gaussian Blur. A window will pop up . . . set the mode to darken. You may also need to lower the opacity.

    Here's the result.

    enter image description here

    I imagine that you could do something similar in your program.

    0 讨论(0)
  • 2020-11-28 18:15

    You could try rotoscopy, like toonyphotos.com does:

    rotoscopy example

    0 讨论(0)
  • 2020-11-28 18:16

    I have not done this myself, but thinking about two steps that might give the image a cartoonish look.

    1. Detect edges, and draw a fairly fairly thick line (a few pixels) on those edges.

    2. Decrease the number of colours in your image.

    0 讨论(0)
提交回复
热议问题