How is the photoshop cutout filter implemented?

11,532

Solution 1

Very old question but maybe someone searching for an answer and maybe this helps. Opencv's findcontours and approxPolyDP functions can do this. But we need to prepare the image before main process. First; find most used N colors with k-means. For example find 8 colors.Find contours for each color and then calculate contourArea for all colors one by one (We will have N=8 layers). After that draw filled contours after approxPolyDP for each color from biggest ContourArea to smaller with its pre-calculated color. My another suggestion is eliminate very small contours while calculating contourArea.

Photoshop cutout effects parameters; Number Of Levels=K-Means-find most used N colors. Edge Simplicity=I guess gaussian blur or other removing noise filters like bilateral filter or meanshift filter with edge preserving will be useful for this step.This step can be executed after K-Means and before finding contours. Edge fidelity=openCV's approxPolyDP epsilon parameter.

Solution 2

Edge detection is usually a Sobel or Canny filter then the edges are joined together with a chain code.
Look at something like the OpenCV library for details

Solution 3

Did you see this post. It explains how to get the same result using ImageMagic, and IM is opensource.

Share:
11,532
fastcall
Author by

fastcall

Updated on June 28, 2022

Comments

  • fastcall
    fastcall almost 2 years

    Photoshop has a lot of cool artistic filters, and I'd love to understand the underlying algorithms.

    One algorithm that's particularly interesting is the Cutout filter (number 2 at the link above).

    It has three tunable parameters, Number of Levels, Edge Simplicity, and Edge Fidelity. Number of levels appears to drive a straightforward posterization algorithm, but what the other sliders do technically eludes me.

    I would think that they're doing something related to Vornoi diagrams or k-means partitionion, but poking around on wikipedia hasn't resulted in anything that maps obviously to what Photoshop is doing, especially considering how fast the filter renders itself.

    Is there any source for technical descriptions of the Photoshop filters? Alternatively, do you have any thoughts about how this particular filter might be implemented?

  • fastcall
    fastcall over 15 years
    This was a good jumping off point for additional googling, but unfortunately GIMP doesn't have a close analog built in. I did find a cool GIMP plugin called pspi, which can load photoshop plugins, but Cutout is one that isn't implemented this way :(