Blurring color images with transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
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 am not on windows. I have many old versions installed on my Mac, but after upgrading delegate libraries, the old versions do not work any longer and won't recompile with the newer delegates.

I really have a hard time believing that the change in result after the alpha channel is turned off is really due to just the blur. I do not see how a gaussian blur (which is circular) can change a rainbow circle into a rounded rectangle and nor how it can change the red to black.

So someone else will have to try to duplicate your results with the image provided on an older version of IM. Sorry I wish I could do that for you, but I cannot.

Perhaps user snibgo or one of the other windows users have an older version of IM that they can use to test.

It might be that an older version of IM can deal with the transparency better, but I would be surprised if you then turn off the transparency and get your rounded rectangle rainbow and the red is turned to black by the process given your input image that has a circular rainbow surrounded by red.
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 »

Here is one way to process the image you have provided to get the results similar to what you want. IM 6.8.7.10 Q16 Mac OSX

Here is the input, the underlying image and the alpha channel.

Image Image Image

Here is what I get from doing the blur in Photoshop CS (very old).

As you can see (below) when the alpha channel is turned off, PS has expanded the region of the rainbow and made the background white elsewhere.

Image Image

In my opinion, IM -blur does not do this automatically and I do not believe it ever did, since that would need a outward boundary diffusion process. IM does not have any diffusion process and the closest is color morphology dilate (which did not do a good job here from my testing). (Neither did -sparse-color voronoi)



My IM processing if you want the whole circle blurred (only works for this circular image):


# line 1 -- read the image
# line 2 -- do a depolar warp to 1/4 height and then back again so that the whole image is the rainbow
# line 3 -- extract the alpha channel of the input
# line 4 -- delete the original and put the alpha channel into the processed image
# line 5 -- blur the image
convert 1in.png \
\( -clone 0 -virtual-pixel edge -distort depolar "%[fx:h/4]" -distort polar "%[fx:h/4]" \) \
\( -clone 0 -alpha extract \) \
-delete 0 -alpha off -compose copy_opacity -composite \
-channel rgba -blur 0x8 \
1in_improc_blur1.png

The following are the polar processed image, the alpha channel and the blurred result

Image Image Image



Now if you only want the border blurred, do this:

# line 1 -- read the image
# line 2 -- do a depolar warp to 1/4 height and then back again so that the whole image is the rainbow
# line 3 -- extract the alpha channel of the input and blur
# line 4 -- delete the original and put the blurred alpha channel into the processed image
convert 1in.png \
\( -clone 0 -virtual-pixel edge -distort depolar "%[fx:h/4]" -distort polar "%[fx:h/4]" \) \
\( -clone 0 -alpha extract -blur 0x8 \) \
-delete 0 -alpha off -compose copy_opacity -composite \
1in_improc_blur2.png

The following are the polar processed image, the blurred alpha channel and the final blurred result

Image Image Image
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.
i alredy said few times, that input is one, i already gave you old distrib of IM, you can try it by yourself, what else can i do with your unbelieving in programms algorythm,it's easy one by the way, it's something like, no, not scale, but something like repeated interpolated outline of the edges of picture, but making it only in the alpha channel leaving these new pixels fully transparent, and making it only in given by blur parameter radius. And them performing usual blur. That is the algorithm taht IM performing to do this unbelievable result.

Heres for you another example

It's sprite from Heroes of Might & Magic 3 (alpha channel is white RGB(255,255,255)

Image

And here is performing blur (-channel RGBA -blur 0x1) in older version of IM, And second is what happened in alpha channel

Image
Image
You see it, Its good and right result. I don't know why IM turn the rest of the pixels to black, i think it's not so important.
Axolotl
Posts: 20
Joined: 2010-10-26T11:40:57-07:00
Authentication code: 8675308

Re: Blurring color images with transparency

Post by Axolotl »

In my opinion, IM -blur does not do this automatically and I do not believe it ever did, since that would need a outward boundary diffusion process. IM does not have any diffusion process and the closest is color morphology dilate (which did not do a good job here from my testing). (Neither did -sparse-color voronoi)
Can you just install the older IM, that i gave you he link (it's few minutes buiseness), and try it by yourself, why someone must make you believe in it. Man, it's even said in the manual. And in manual examples exactly the same result that i show you, and one you cannot believe)))
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 have responded in the bug thread, viewtopic.php?f=3&t=24665

In brief: I agree with Axolotl. Pixels that are blurred used to be weighted by their alpha, but are no longer. The documentation describes the old behaviour, not the new behaviour.

In the old versions, when all of the pixels used to calculate a blurred pixel are transparent, then all their weights are zero, so none of the colours of those pixels are used, and the result is fully transparent. As none of the colours are used, IM uses an arbitrary transparent colour. Transparent black is a good as any other colour.
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 »

I should point out that using "-channel RGBA,sync" instead of "-channel RGBA" does seem to weight by alpha, but has other effects that are undesirable in the rainbow example.
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 »

Can you just install the older IM, that i gave you he link (it's few minutes buiseness), and try it by yourself, why someone must make you believe in it. Man, it's even said in the manual. And in manual examples exactly the same result that i show you, and one you cannot believe)))
Axolotl

I would have tested it if I could. I used to be able to go way back in IM versions for testing my scripts and confirming bugs. But I cannot go back that far any longer. However, user snibgo did the tests and his results have convinced me that I was wrong about IM being able to do that properly in the past. My apologies.

So we need to wait for the IM developers to be able to look into this and get back.
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 »

Another workaround uses distort instead of resize:

Code: Select all

convert colorcone.png -filter Gaussian -define filter:sigma=5 -distort SRT 0 ccc.png
snibgo's IM pages: im.snibgo.com
Post Reply