Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gaussian blur leads to white frame around image

Tags:

c#

image

wpf

blur

I'm applying a blur effect to an image in WPF like so:

<Image ClipToBounds="True">
    <Image.Effect>
        <BlurEffect Radius="100" KernelType="Gaussian" RenderingBias="Performance" />
    </Image.Effect>
</Image>

As you can see, the radius is large, because the image is large and I need it to be really blurry. However, for a radius that large I'm getting a light frame around my image as seen in the attached image. How can I suppress this?

In case you're wondering: The result is the same not matter the RenderingBias. A border is also produced in quality-mode.

White border around image

like image 498
Thorsten Dittmar Avatar asked Jun 04 '11 09:06

Thorsten Dittmar


People also ask

What does a Gaussian blur do to an image?

The Gaussian blur is a way to apply a low-pass filter in skimage. It is often used to remove Gaussian (i. e., random) noise from the image. For other kinds of noise, e.g. “salt and pepper” or “static” noise, a median filter is typically used.

Why is my Gaussian blur not working?

2 Correct answersCheck if Effect > Document Raster Effects > White is checked for Background. Start by checking your hardware acceleration settings and also verify the raster effect DPI setting. Reverting to software-only mode or lowering the DPI may fix things.


2 Answers

What's happening is the result of a blur together with the ClipToBounds. Since you're using a Gaussian blur, the edges are going to naturally blend into the background (white).

Applying ClipToBounds basically cuts off where it would otherwise have been blending into the white, hence why you get a white frame.

Unless you're willing to clip the image even more, unfortunately this is just how blurs work.

Screenshot of cliptobounds

like image 124
LongZheng Avatar answered Sep 20 '22 18:09

LongZheng


Before blurring, You can pad the image using the pixels from the image border. By doing that you can assure that the blurred pixels around the border will be blurred using pixels of similar color and the whitish border will be gone. Of course, after blurring crop the image back to its original size.

like image 34
Gilad Avatar answered Sep 20 '22 18:09

Gilad