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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blurring color images with transparency

Post by magick »

Add the sync flag to the -channel argument, as in
  • convert colorcone.png -channel rgba,sync -blur 0x5 cc2.png
Does that return the expected results? See http://www.imagemagick.org/script/comma ... hp#channel for an explanation.

In Anthony's morphology comments, he says:
No 'Sync' involved-- convolution is simple greyscale channel operation (channels treated independently).

Channel 'Sync' flag and alpha channel enabled-- weight the color channels with Alpha Channel so that transparent pixels are not part of the results.
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 »

Sync helps some, as user snibgo mentioned earlier, but does not produce the same result. It leaves a slight black shadow whereas the old version does not.

Compare the attached images and also look at them with -alpha off to see why. The old version propogated the underlying image further outward so that the alpha channel did not blend it with some of the black surrounding. The newer code does not propagate the colors far enough and thus there is still some blending of partial transparency with the black that shows in the results. This likely due to improper alpha weighting or from a different alpha weighting method that is not as good as the old alpha weighting. This may have been an oversight on Anthony's part or a bug in his code.

Correct older versions of IM before 6.8.4.0 without sync results of command with and without alpha

im6840 convert colorcone.png -channel rgba -blur 0x5 cc2.png

Image Image



Incorrect current version 6.8.7.10 with sync results of command with and without alpha

convert colorcone.png -channel rgba,sync -blur 0x5 cc2.png

Image Image


Original image:

Image Image


If the current code is fixed to work the same with the sync flag added, then the -blur docs should explain that, since the sync flag was not needed to achieve the good results in older versions of IM. I suspect it was overlooked when the switch to the morphology blur was made and no one until now noticed the issue.
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 »

Sync also has an unfortunate effect on the colours: we don't get a regular transition between the colours. The is particularly visible at the edge of the rainbow circle, where yellow cyan and magenta predominate at the expense of red green and blue.

I will also mention "-gaussian-blur" suffers the same problem as "-blur", that pixels are no longer weighted by alpha.
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 »

As mentioned, we have a request into Anthony to review his code and fix the web pages. We need a few days to give him a chance to respond.
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 »

As snibgo has pointed out earlier, the following command currently produces correct looking results. So that code might give you a clue how it was done correctly.


convert colorcone.png -filter Gaussian -define filter:sigma=5 -resize 100% cc_gaussfilter5.png
convert cc_gaussfilter5.png -alpha off cc_gaussfilter5_aoff.png

Image Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Blurring color images with transparency

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.8-0 Beta available by sometime tomorrow. Thanks.
Post Reply