Blur and Restore Alpha - RealWorld forums

Log-in or register.

Blur and Restore Alpha

on October 31st 2013

Blur and Restore Alpha
Blurs and image using gaussian blur and then restores the alpha values of the pixels to what they where before the blur.
This is good for when you had a shape drawn on a transparent background that used anti-aliasing. The anti-aliasing is done by adjusting the alpha value of the shapes edge, which can be hard to keep without also blurring the inner pixels alpha when blurring normally.


Configuration.AddSlider("blurRadius", "Blur Radius", "", 1, 200, 6);


var blurRadius = Configuration.blurRadius;

var image = Document.RasterImage;
var w = image.sizeX;
var h = image.sizeY;

var clone;
clone = Document.Duplicate();
clone = clone.RasterImage;

var blur = Operation.Create("Raster Image - Blur");
blur.Type = 0;
blur.Radius = blurRadius;
Operation.Execute(blur, image);

var x, y, alpha;
for (x=0; x<w; x++){
for (y=0; y<h; y++){
alpha = clone.GetPixelAlpha(x, y, 0, 0);
image.SetPixelAlpha(x, y, 0, 0, alpha);
on November 4th 2013

I should really work on the documentation some more. The Blender object can help with the last loop and speed up things significantly. You can replace the loop with this command and it will copy the A channel from clone to image:

Blender.Compose(image, 0, 0, w, h, clone, 0, 0, 0, Blender.OpMapChannels,
    Blender.MapChannels(Blender.ChEmpty, Blender.ChEmpty, Blender.ChEmpty, Blender.ChA,
                        Blender.ChEmpty, Blender.ChEmpty, Blender.ChEmpty, Blender.ChA));
Page views: 2049       Posts: 2      
Select background
What about ICL files?
Vista & Win 7 icons