Tuesday, July 5, 2011

Sobel filter cleaned up

This is another case of something I did for fun coming in handy later. After I learned the basics in the beginning with the help of the GStreamer Plugin Writer's Guide (a very good piece of documentation indeed), I wanted to do a moderately difficult task for self-assessment before getting started with real porting work. I chose to put this semester's DIP class knowledge to use, and write a filter that calculates gradient magnitude on the luminance channel of I420 video streams using the Sobel operator.

The original plans for the project included an idea about smart sharpening, a procedure useful in CCD noise removal. (Details here.) Those who read hypertext depth-first already see the point: it requires edge detection. (At the time that article was written, the GIMP edge detection plugin used in the article was implemented with the Sobel operator.) So I cleaned up the code, and added a property that can turn border mirroring on/off. If it's on, pixel indices in horizontal and vertical gradient calculation are clamped inside the frame boundaries, effectively mirroring the border pixels outside the frame, so that the operator can be applied to them. (The gradient is otherwise undefined for the borders.) If it's off, the border pixels are set to zero instead. The latter is faster, the former gives meaningful data on the borders. I believe that for most cases, off is the better choice.

The new code is up on github.

No comments:

Post a Comment