Page 1 of 1

Antialiased white border around PNG with transparent B/G

Posted: 2007-11-27T04:20:35-07:00
by marcusj
I've been trying to create an anti-aliased (white) border of 1 pixel around a PNG image that has a transparent background without success.

I used PerlMagick to make a script that I have subsequently found much better done here http://www.fmwconcepts.com/imagemagick/ ... /index.php. Basically, I understand how to make this:

Image

but I don't understand how to add the edge/outline to the original image below in an anti-aliased style.

Image

Is it possible?

Re: Antialiased white border around PNG with transparent B/G

Posted: 2007-11-27T13:07:29-07:00
by fmw42
You can try one of 3 things:

1) use -blur to blur the edge slightly with the transparent background

2) magnify your original image by 2 or 4 in each direction, then extract the edge result, then minimize the result back to your original size (use -filter lanczos -resize)

3) modify the magicwand script to antialias the binary image before it extracts the outline. See the concept behind the feather script at http://www.fmwconcepts.com/imagemagick/ ... /index.php

Hope one of these approaches helps

Re: Antialiased white border around PNG with transparent B/G

Posted: 2007-11-27T18:19:32-07:00
by anthony
Of course creating anti-aliased areas that can piece together (using blend or add composition)
would be the ultimate form of anti-aliased segmentation of an image. However that seems to be much more difficult then a pure B/W mask.

Please let us know what you try and what you come up with, as I and probably a lot of other people would like to know what you conclude from the various methods, and the best result you achieved.

Re: Antialiased white border around PNG with transparent B/G

Posted: 2007-11-28T08:00:17-07:00
by marcusj
Great, I've made some progress... ...and sorry for my hopeless lack of understanding of bitmap manipulation.

In my (PerlMagick) script I now make a new image with a transparent background of the same dimensions and then blur it. Then I Composite it onto the original image. Right now I'm using the Screen composite method which seems to get closest to the result.

Actually, I've been looking around the examples pages some more and it looks like the stuff here is really close to the result I want to achieve anyway. That is to say, I want to make an image that is (already) on a transparent background to get a 'nice edge' so that it can be placed on a 'noisy background' and still stand out. The specific example on the examples page starts out with an image on a white background (i.e. no transparent layer). So would I be close with something like the following sequence?
  • convert myImageWithTransparentBackground.png <some command to extract the alpha mask> difference.png
  • convert difference.png -bordercolor black -border 5 -threshold 10% -blur 0x3 halo_mask.png
  • convert myImageWithTransparentBackground.png -bordercolor white -border 5 halo_mask.png +matte -compose CopyOpacity -composite myImageWithTransparentBackgroundAndHalo.png

Re: Antialiased white border around PNG with transparent B/G

Posted: 2007-11-30T07:04:10-07:00
by marcusj
Finally I have just about settled on a very slightly tweaked version of fmw42's suggestion:
  • Expand the canvas with transparent background to add a 1-pixel border all around, just to make sure that there's going to be room for the outline.
  • Double the size of the image with -resize.
  • Use Fred's magicwand to make an outline (0,0 -t 10 -f mask -m edge -c color="trans" -r inside).
  • Convert the black background (couldn't persuade magicwand to do this) to transparent using convert -channel A -fill none -transparent black.
  • Composite the white outline onto the enlarged image with -compose Over.
  • Halve the size of the composite with -filter Lanczos to get the final image.
Of the ~2000 images, this has worked well for about 95%. That saves me a whole bunch of Gimp / Photoshop time :D .

Thanks!

Re: Antialiased white border around PNG with transparent B/G

Posted: 2007-12-04T12:29:26-07:00
by fmw42
Yes, you are right. My magicwand script only makes a binary outline image and does not allow the black area to be output as transparent. But your modification afterwards is what I would have done. Glad to hear it has worked out.