BoltBait's Pages - Feather Filter

Sarcasm - just one of the services I offer...


Paint.NET Feather Filter

My original question was: Is there a way to Guassian Blur only the edges of a selection?

For example, when pasting a selection on the top of another bitmap, the edges are usually harsh. I usually use the Lasso to carefully select around the edges and apply a Guassian Blur (2) to the edges. This makes the pasted area appear more naturally like part of the original picture.

I usually use the Lasso tool to Gaussian Blur the edges of the objects that I want to paste into my work.  This works OK, however being accurate with the Lasso tool is a bit difficult.

What I wanted was a "Feather" filter similar to other graphics programs.

A friend of mine, Illnab1024, sent me the source code to the Gaussian Blur function out of Paint.NET and I wrote a Feather Filter based on that code.


The Idea

My original thought was to follow the selection path and Gaussian Blur the pixels just on the inside of the selection path.  Unfortunatly, the selection path is not available to effect DLL's in Paint.NET.

My second thought was to modify the Gaussian Blur filter to only apply the blur effect if the current pixel was an edge pixel.  I calculate if the current pixel is an edge by looking at 4 pixels: the one just above, just to the left, just to the right, and just below the current pixel.  If any of those pixels are transparent, I Gaussian blur the current pixel with a radius of 2.  This is exatly what I did and it worked out perfectly.


The Effect DLL

You can download the precompiled effect DLL here: Feather.dll

Just drop this file in your \program files\Paint.NET\effects directory and you should be all set.


Instructions for Use

This might seem a little odd to use at first, but once you get the hang of it, your compilation pictures will be better for it, I'm sure!

1) Start with your source image on the background layer.  In this case I will use this nice patch of grass:

2) Create a new layer that is completely transparent.  On this layer, paste the object you wish to combine with your original image.  I will choose this screwdriver:

Notice how the edges of the screwdriver are rough and it doesn't really look like part of the original image.

Also, notice in the layers menu, you can see that the area around the screwdriver is transparent (Paint.NET shows transparent areas using a gray checkerboard pattern).  This is critical for my feather filter.  Transparent areas are how it knows where to feather.

3) With layer 2 selected, run the Feather Filter.


Notice how the rough edges are gone and the screwdriver looks as if it is part of the background image.  Also notice that the middle of the screwdriver is no more blurry than it was originally.

At this point you can Merge Down layer 2 with the background to complete your image.


Source Code

As I really only changed a few lines of the Gaussian Blur function, I'm going to skip posting all of that code--its pages and pages long!  If you really NEED to know how I did it, just email me and I'll get back to you.




Sunday, January 27, 2008