views:

592

answers:

3

I need Action Script3 / Pixel Bender blur filter with mapping capability’s.

We have such image, we want to apply such blur map to get such result

alt text

Its also known as Compound Blur effect.

Has anyone seen it done with AS3/ Pixel Bender?

Does Anyone know where to download such effect with source?

+3  A: 

You may just draw a blurred image(with alpha channel changed to the blur value map) on its original to simulate the effect.

Because pixel bender in Flash does not support loops, it is difficult to create a good blur filter.

Andy Li
And what about doing it with mix of AS3 and PB? Is it possible?
Blender
What about doing this multiple times (pb filter looped with as3), say 5, and then composting it all back together with pixel blender?
PiPeep
Or you could separate the image into a grid, and blur each piece correspondingly.
PiPeep
Actually pure AS will do the job as the suggestion in my answer... BTW, will the effect be used in real-time video processing or just for a single image?
Andy Li
real-time video processing.
Blender
Do it this way. Sampling multiple pixels in Pixel Bender is *slow*. You’re far better off simulating compound blur using the built-in Flash blur and a mask.
Daniel Cassidy
+2  A: 

The following .pbk should pretty much do it. You can take a look at the comments to see how you would deepen the blur effect.

<languageVersion : 1.0;>
kernel NewFilter
<   namespace : "Your Namespace";
    vendor : "Your Vendor";
    version : 1;
    description : "your description";
>
{
    input image4 src1;
    input image4 src2;
    output pixel4 dst;

    void
    evaluatePixel()
    {
        float2 pos = outCoord();

        // based on the current whiteness of pixel in src2 blur by a percentage.
        float4 val = sampleNearest(src2,pos);
        float percent = val[0];

        // this takes into account only the closest level of pixels to make the blur more in depth 
        // you can add the next 16 or even the 24 after that. 
        float4 pix = sampleNearest(src1,pos);
        float4 pixNE = sampleNearest(src1,float2(pos.x+1.0, pos.y+1.0));
        float4 pixE = sampleNearest(src1,float2(pos.x+1.0, pos.y));
        float4 pixSE = sampleNearest(src1,float2(pos.x+1.0, pos.y-1.0));
        float4 pixS = sampleNearest(src1,float2(pos.x, pos.y-1.0));
        float4 pixSW = sampleNearest(src1,float2(pos.x-1.0, pos.y-1.0));
        float4 pixW = sampleNearest(src1,float2(pos.x-1.0, pos.y));
        float4 pixNW = sampleNearest(src1,float2(pos.x-1.0, pos.y+1.0));
        float4 pixN = sampleNearest(src1,float2(pos.x, pos.y+1.0));

        float4 result;
        // the result is the whiteness percentage of the original pixel averaged with the surrounding pixels.
        // if you added more of the surrounding pixels you can consider them in the weighted average also and get a deeper blur.
        result[0] = percent*pix[0]+(1.0-percent)*(pixNE[0]+pixE[0]+pixSE[0]+pixS[0]+pixSW[0]+pixW[0]+pixNW[0]+pixN[0])/8.0;
        result[1] = percent*pix[1]+(1.0-percent)*(pixNE[1]+pixE[1]+pixSE[1]+pixS[1]+pixSW[1]+pixW[1]+pixNW[1]+pixN[1])/8.0;
        result[2] = percent*pix[2]+(1.0-percent)*(pixNE[2]+pixE[2]+pixSE[2]+pixS[2]+pixSW[2]+pixW[2]+pixNW[2]+pixN[2])/8.0;
        result[3] = pix[3];

        dst = result;
    }
}
dennisjtaylor
it will not work because if you’ll look at their sources you’d see - they use 2 filters vert and hor to do blur, 2 times to compare blur map to original - madness), and btw they have formula just from 0 to 6 only exact numbers 1 2 3 4 5 6 so it will not work for me(
Blender
My post has been edited to reflect one possible implementation of the desired blur effect using pixel bender. Even though this approach always looks at the surrounding pixels of each pixel even if it does not blur them the performance advantages of pixel bender should compensate for the extra work.
dennisjtaylor
+3  A: 

I have an very old pre-pixel bender version of this effect here: http://www.quasimondo.com/archives/000564.php (as2 source included)

It works by creating several blurred bitmaps with the blur radius increasing from 0 (or the minium radius you choose) to the maximum radius. The more blur steps you do the better the quality will be. Using the paletteMap filter you create masks for each blur layer in such a way that there is a gradient overlap between each consecutive layer. Then you draw each blur layer over the next using its mask.

This second blending phase I would probably now rather do with pixel bender.

Quasimondo