Blurring color images with transparency

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Blurring color images with transparency

Post by Axolotl »

Hi, i first made a topic in the main forum because i thought that it was some my misunderstanding, but now it seems more like a Bug
Here the topic in Main forum
viewtopic.php?f=1&t=24658

Here is link to manual chapter
http://www.imagemagick.org/Usage/blur/#blur_channel
where it is said that -channel RGBA -blur works fine with transparency...and it realy worked

Yes, it worked fine in old versions of IM. But now it works buggy :(

Here the example:

This is Unput files with alpha channel and without
Image Image

Here is How it worked in 6.6.5 with using -channel RGBA -blur and in right picture we see what happened in alpha channel if we remove transparency

ImageImage

.............................................................

And here is how it works in new (6.8.6) version of IM :(
Image Image

Using on Windows 7 64bit - version of IM that works buggy - ImageMagick-6.8.6-Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Blurring color images with transparency

Post by fmw42 »

I do not see how it is possible to get the second result from the first image with a simple -channel rgba -blur. The background data under the transparency is totally different. You need to have the background data of the second image with the alpha channel of the first image to get the result you want. I suspect you are not using the same input images for your two systems.

Post the input image from the second result before the blur and look at it with the alpha channel turned off.
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Re: Blurring color images with transparency

Post by Axolotl »

Of course the input image is the same. And why it's not possible, do you think?
Even in IM manual said that it must work that way, and you can see the examples here http://www.imagemagick.org/Usage/blur/#blur_channel
Photoshop works similiar way blurring with transparency...why do you doubt in that.
You can try it yourself with old version of IM or in Photoshop. So it's definitly just a bug, so i submit it. Hope for soon fixing this, because it already worked in earlier verisons.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Blurring color images with transparency

Post by fmw42 »

And why it's not possible, do you think?
It is not possible with a simple blur of a small amount to make the rainbow circle into a rounded rectangle and change the background color from red to black.

Either you have two different images or other processing was done beyond a simple blur to change the structure of the image under the transparency. A simple blur will not do all of what you see.

Unfortunately, I cannot go back before IM 6.8.6.9 to test. Perhaps one of the other users might be able to do so and confirm.
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Re: Blurring color images with transparency

Post by Axolotl »

fmw42 wrote:
And why it's not possible, do you think?
It is not possible with a simple blur of a small amount to make the rainbow circle into a rounded rectangle and change the background color from red to black.

Either you have two different images or other processing was done beyond a simple blur to change the structure of the image under the transparency. A simple blur will not do all of what you see.

Unfortunately, I cannot go back before IM 6.8.6.9 to test. Perhaps one of the other users might be able to do so and confirm.
Man, I am confirming that. It's bug testing topic, It's for the authors of program, they know better how their program worked, they did that algorithm that you cannot belive. More than that it's quite coomon way to handling blur with transparency. So the only thing i'm waiting is to fixing that bug))))
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Blurring color images with transparency

Post by fmw42 »

Post a link to the exact input images being used on both servers to be sure you don't have two images of the same name, but different non-transparent channels. Upload them from each server. I still find it inconceivable that blurring will change the non-transparent channels from a circle to a round rectangle and the red to black.
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Re: Blurring color images with transparency

Post by Axolotl »

fmw42 wrote:Post a link to the exact input images being used on both servers to be sure you don't have two images of the same name, but different non-transparent channels. Upload them from each server. I still find it inconceivable that blurring will change the non-transparent channels from a circle to a round rectangle and the red to black.
Oh, man, it's bug theme, There is similiar theme in user topic, let's leave this topic to the authors an tech support. I will answer you in the User theme.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Blurring color images with transparency

Post by snibgo »

I am responding here, rather than in users, as I do consider this to be a bug.

It would help if Axolotl supplied the exact commands he used. The behaviour was as he described until IM v6.8.3-0. From v6.8.4-0 it was different. I don't have intermediate versions to test, but changelog.txt says "-blur" changed at 6.8.4-0 to use morphology. I suspect that has created the difference.

The old behaviour wasn't an "outward boundary diffusion process". With a blur, new pixel values are calculated by mixing values from surrounding pixels. Under the old behaviour, pixels were weighted by their alpha before mixing. The red pixels had alpha=0 so did not participate in the mixing. Hence the rainbow colours spread, unmodified, into the transparent area. From v6.8.4-0 this weighting no longer occurs.

The documentation describes the old behaviour, so is wrong for recent versions of IM.

I have renamed the image supplied by Axolotl as colorcone.png. It is a rainbow circle on a transparent red background.

Image

I do three commands, using IM v6.8.3-0.

Code: Select all

set I=%IMG683%

"%I%convert" colorcone.png -alpha off cc1.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 cc2.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 -alpha off cc3.png
Image

Image

Image

I then do the same three commands using a more recent IM, v6.8.7-5.

Code: Select all

set I=%IMG6875%

"%I%convert" colorcone.png -alpha off cc1b.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 cc2b.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 -alpha off cc3b.png
Image

Image

Image
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Blurring color images with transparency

Post by snibgo »

Here is a very simple example that shows the problem. We blur a transparent red pixel with an opaque green pixel. Under the old behaviour, the resulting pixels are both green, with no red component, and varying transparency.

Under more recent versions, the red bleeds into the green.

Code: Select all

D:\web\im>"c:\program files\imageMagick-6.8.3-Q16\convert" xc:#f000 xc:#0f0f +append -channel RGBA -blur 0x5 txt:
# ImageMagick pixel enumeration: 2,1,65535,srgba
0,0: (    0,65535,    0,30153)  #0000FFFF000075C9  srgba(0%,100%,0%,0.460105)
1,0: (    0,65535,    0,35382)  #0000FFFF00008A36  srgba(0%,100%,0%,0.539895)

D:\web\im>"c:\im\ImageMagick-6.8.7-5\convert" xc:#f000 xc:#0f0f +append -channel RGBA -blur 0x5 txt:
# ImageMagick pixel enumeration: 2,1,65535,srgba
0,0: (53.9834%,46.0166%,0%,0.460166)  #8A3275CD000075CD  srgba(53.9834%,46.0166%,0%,0.460166)
1,0: (46.0166%,53.9834%,0%,0.539834)  #75CD8A3200008A32  srgba(46.0166%,53.9834%,0%,0.539834)
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Blurring color images with transparency

Post by snibgo »

See also Resize and resample in alpha-multiplied light by NicolasRobidoux which (if I understand correctly) justifies the old behaviour.

I have found a workaround to reproduce the old behaviour:

Code: Select all

convert colorcone.png -filter Gaussian -define filter:sigma=5 -resize 100%% cc.png
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Blurring color images with transparency

Post by fmw42 »

I do three commands, using IM v6.8.3-0.
CODE: SELECT ALL
set I=%IMG683%

"%I%convert" colorcone.png -alpha off cc1.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 cc2.png

"%I%convert" colorcone.png -channel RGBA -blur 0x5 -alpha off cc3.png

OK. You have me convinced. I did not think it would spread the colors that way. The change occurred when -blur was replaced by -morphology blur and I guess Anthony did not take that issue into account for transparency.

Thanks for testing. As I said earlier I am no longer able to go back to versions before 6.8.6.9, though I have numerous versions that I used to be able to use.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blurring color images with transparency

Post by magick »

The -blur option appears to be working correctly.  Blur looks at a neighborhood of pixels.  As such when there is a transparent pixel next to an opaque colorful pixel, a blending occurs and the result is a half-transparent pixel.   Since colorcone has a transparent red background, you end up with a blended red halo.   With that in mind, we returned reasonable results with this command:
  • convert colorcone.png -background none -alpha Background -channel RGBA -blur 0x5 cc2.png
However, that just changes the red background to black.  We tried the conversion with ImageMagick 5.2 which has a blurring algorithm from 2002 and it returns the same results we're getting today with
  • convert colorcone.png  -channel RGBA -blur 0x5 cc2.png
suggesting the algorithm is working as expected.

You can also blur the colorful channels independently (no alpha blending) with
  • convert colorcone.png -blur 0x5 cc2.png
or all channels independently (no alpha blending) with
  • convert colorcone.png -blur 5x2 -channel a -blur 5x2 cc2.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Blurring color images with transparency

Post by snibgo »

In that case, the documentation at http://www.imagemagick.org/Usage/blur/#blur_channel is wrong. The example images as shown by the commands there no longer work as described.

The page says:
The reason that blurring with the alpha channel produces no orange colors as it did previously, is that when the "-blur" operator sees that the alpha channel is involved (according to the current "-channel" setting), it will only blur using the pixels which are visible according to that alpha channel. If the alpha channel is not involved, it will completely ignore it, and the fully-transparent red will blur with the yellow to produce various shades of orange.
The example images include:

Code: Select all

convert -size 70x70 xc:none -fill yellow -draw 'circle 35,35 20,25' yellow_circle.png

convert yellow_circle.png -channel RGBA -blur 0x8 yellow_blurred_RGBA.png
The blur produces no colour mixing under versions 6.5.8-8, 6.6.0-8, 6.7.9-6, 6.8.0-9, 6.8.1-10, 6.8.2-0 and 6.8.3-0.

The new behaviour, which blurs the yellow with the colour under the full transparency, occurs with versions 6.8.4-0, 6.8.5-0, 6.8.6-0 and 6.8.7-0.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blurring color images with transparency

Post by magick »

Anthony writes and maintains those pages. We have an e-mail pending with him, hopefully he will respond soon.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Blurring color images with transparency

Post by fmw42 »

I would agree with snibgo that -blur currently is not handling the alpha channel weighting correctly.

I had originally disagreed, but his examples with older versions of IM seem to show otherwise. The change probably occurred at 6.8.4.0 when -blur was replaced by Anthony's -morphology blur. So test an older version not too much older than 6.8.4.0. For example try 6.8.3.0 as snibgo had used or one of the other versions he used to test.
Post Reply