views:

164

answers:

3

I'm trying to find out what effects the Photoshop "Poster edges" filter is composed of. It seems it's a combination of edge detection and posterization, but I haven't been able to duplicate it, not even close, with these so I guess I'm missing something. The image below shows the same image before and after the Poster edges filter:

alt text

I've tried performing posterization (and quantization) on the image, along with edge detection using Sobel, but apparently Photoshop is doing something different as the results are very different. Basically the posterization looks very different and edges are very weak compared to the photoshop filter.

So does anybody know how the Poster edges filter is implemented, or have any idea what image-processing should be done to achieve the latter image from the former.

Not that it really matters, but I'm using Java, and my image filtering code is based for the most part on the filters found here: http://www.jhlabs.com/ip/filters/index.html

Edit Description of the filter from adobe.com:

Poster Edges Reduces the number of colors in an image (posterizes it) according to the posterization option you set, and finds the edges of the image and draws black lines on them. Large broad areas have simple shading, and fine dark detail is distributed throughout the image.

A: 

I suspect you have to do this at several scales, in order to filter the edge response.

  1. Run your edge detection at several levels(scales) of a gaussian smoothed pyramid of the input image [sigma_min, sigma_max]
  2. Then, either sum or select maximum edge magnitudes across scales
  3. Posterize with original image (blend ?)
nav
You're probably on the right track, and this is pretty close to what I'm doing, but I'm looking for something that tells me exactly what to do. I've done a _lot_ of trial and error with different combinations and it still isn't producing the desired result.
TuomasR
An exact solution cannot be suggested without looking at the source code. Can you share it ?
nav
@nav: I could, but since the code doesn't do the trick (the result is wrong as 99% chance is that the sequence of effects is incorrect and lacking), I don't see the value in it. What I'm looking in this case is an answer that says "The result can be achieved with X, Y and Z". The answer in this case is contains words "suspect", "either" etc.
TuomasR
@nav: Hmm... premature enter-keyaction there... cut my comment short. To sum it up: the problem isn't the existing source, the problem is that I don't know how to achieve the effect. What you do describe is similar to the other anser, but the actual solution seems to lie in a detail that's being missed, instead of the actual parameters to the existing filters. Photoshop does something that hasn't been pointed out here and I haven't figured out.
TuomasR
A: 

Copy the original image and then apply a PosterizeFilter. Then apply EdgeFilter, GrayscaleFilter and InvertFilter to the copy. Finally multiply the posterized original with the copy. At that point you should have something close to Poster edges.

Diadistis
With that I get this: http://img.skitch.com/20101010-m9y5eeqbtmkkug7xqm9ssihxmr.jpg Left is the Photoshop -version, right is the programmatically created.
TuomasR
This is what I got by following the same procedure in photoshop http://img137.imageshack.us/img137/8885/89390115.png
Diadistis
Hmm... I wonder if I'm doing something wrong. Can you try it with this? http://img.skitch.com/20101010-qm28e4wrr1i9dceta4twfedcbd.jpg
TuomasR
Not as good as the first one I have to admit: http://img135.imageshack.us/img135/3664/13699800.png
Diadistis
Are you trying to replicate the "Scanner Darkly"/"Waking Life" effect?
Diadistis
The "Scanner Darkly" comparison is pretty close. I think the problem is the color levels in the second image. The first one is more suitable for the filtering, but the second image has bad colors. So the solution might be toying with the colors / color levels before filtering the image.
TuomasR
Sorry mate, I've tried several combinations to replicate the effect with no luck...
Diadistis
The "Scanner Darkly" effect is also known as rotoscoping - maybe that will help you find more relevant info?
Matt Ball
A: 

Regarding the edges: I would assume that Photoshop uses something more sophisticated than a simple derivative filter (like Sobel) for edge detection. There are edge detection algorithms that try to find only "salient" edges, i.e. those that are relevant to human vision, edges a human artist would draw if he does a line sketch. An old and (rather) simple algorithm that goes in this direction (at least a bit) is the Canny edge detector. You should be able to find an implementation of this one. Google for "salient edges" for current research literature, but don't expect implementations or nice pseudocode in research papers.

Regarding posterization: Given their talks at SIGGRAPH, the Adobe guys are very much into bilateral filtering (please Google, I can't link any more), a smoothing technique that preserves important edges. I think if you apply the bilateral filter and posterize afterwards you should come closer to the look you want. Unfortunately, efficiently implementing the bilateral filter is not trivial.

David C Schneider
Thanks for the pointers. I actually tried canny edge detection, but the results for the test images were actually a little weaker than with Sobel (seems like Canny produced weaker edges, although a little more accurately, and I'm looking for stronger edges, but it doesn't have to be that accurate). Googling bilateral filtering gives results that I think you might be right about it. Unfortunately looking at the algorithm it also seems very much non-trivial. Gotta dig up those old university math books...
TuomasR
Canny edges are, indeed, "weak" in the sense that they are just 1 pixel wide. Canny edges just indicate that there is an edge there. I would try to detect "good" edges first and then "grow" them, probably proportional to their length, using, for example, dilation.
David C Schneider
After a few test, I'm now getting results which are starting to look like PS's poster edges. Still quite not there, but now I think it's more a matter of tuning the parameters. A big thanks for your help. Now just to get the filtering to run in reasonable time :P
TuomasR