# Blur, GaussianFilter and ImageConvolve doesn't work on some images

In versions 8.0.4 and 9.0.1 applying Blur to an image gives expected result:

img = Import["http://i.stack.imgur.com/UsJTa.png"]

blurred = Blur[img, 5]

ColorSeparate[blurred]


But in the recent versions Blur as well as GaussianFilter and ImageConvolve simply do nothing (checked with versions 10.0.1, 10.4.1, 11.1.1 and 11.2.0):

blurred = Blur[img, 5]
ImageData[blurred] == ImageData[img]


True

filtered = GaussianFilter[img, 5]
ImageData[blurred, Byte] == ImageData[img, Byte]


True


Why this happens? Is it a bug? Is there a workaround?

• This seems like a bug, as an example in the manual no longer works correctly in 11.2. d = Image[DiskMatrix[23, 81], "Bit"]; GaussianFilter[d, {10, 3}] – xsk8rat Mar 1 '18 at 20:39
• Strongly related: mathematica.stackexchange.com/q/20494/280 – Alexey Popkov Jun 27 '18 at 12:46
• @xsk8rat This example seems to work as expected in versions 11.3 and 12.0. But it has nothing common with the example in the question because has no alpha-channel. – Alexey Popkov Sep 23 '19 at 18:55

Starting from Mathematica 10.0 such functions as Blur, GaussianFilter, ImageConvolve etc. don't affect alpha channel of an Image anymore. This change makes their behavior consistent with such related functions as ImageAdjust, Dilation, ImageEffect etc. which didn't change the alpha channel in previous versions. Hence it looks more like a bug fix.

To reproduce the old behavior, we should remove the ColorSpace information which is used to determine which color channel is the alpha channel. According to the Documentation page for ImageColorSpace, Automatic colorspace means that "no color space specified". Let us try:

Image[Blur[Image[img, ColorSpace -> Automatic], 5], ColorSpace -> ImageColorSpace[img]]

ColorSeparate[%]


Equivalently one can apply Blur separately to each channel:

ColorCombine[Blur[#, 5] & /@ ColorSeparate[img], ImageColorSpace[img]]


Another way is to use a function which is still applied to the alpha channel.

As of Mathematica 11.2.0, ImageFilter works with all the channels:

ImageFilter[Mean[Flatten[#]] &, img, 3]
ColorSeparate[%]


A bit surprisingly, but ImageCorrelate is also still applied to the alpha channel (Mathematica 11.2.0):

ImageCorrelate[img, GaussianMatrix[5]]
ColorSeparate[%]


I don't know why the exception is made for these two functions. May be a bug?

• For the down-voter: please comment why you down voted? I fail to see your reasoning. – Alexey Popkov Sep 23 '17 at 5:55

This is happening because the Imagedata in your image is all zeros

img = Import["http://i.stack.imgur.com/UsJTa.png"]


When you filter (or Blur or ImageConvolve) an image of all zeros, you get back an image with all zeros. The reason you see anything at all is because the alpha channel is sometimes zero and sometimes one. You can verify this by removing the alpha channel:

RemoveAlphaChannel[img]


So the bottom line is that Blur (and the other functions, presumably) only work on the image data, and not on the alpha channel.

To make Blur will work on this image, you can place the alpha channel into a data channel. Here's one way:

img2 = Image[ImageData[img] /. {r_, g_, b_, alpha_} -> 1 - alpha];
Blur[img2, 5]


• I'm still unsure that this behavior is in accord with the Documentation statement for Blur: "For multichannel images, it operates separately on each channel." So actually "it operates separately on each channel" EXCEPT the alpha channel (which is a part of ImageData)? – Alexey Popkov Sep 21 '17 at 0:06
• Alpha channels are always tricky to handle since they are so different from color channels, but yes, the functions are not being applied to the alpha channel. – bill s Sep 21 '17 at 0:12