Menu

drawing ellipse on transparent canvas creates unwanted 'halo'

Help
Erik
2015-11-19
2020-03-06
  • Erik

    Erik - 2015-11-19

    gm convert -size 200x200 xc:"transparent" -fill "#4D3681" -stroke "#FF0000" -draw "ellipse 100,100 50,100 0,360" test1.png
    draws an opaque unwanted black ring about the ellipse

    gm convert -size 200x200 xc:"transparent" -fill "rgba(255,255,255,255)" -stroke "#FF0000" -draw "ellipse 100,100 50,100 0,360" test2.png
    draws an opaque unwanted white ring about the ellipse

    How to get an ellipse painted on a transparent background with an antialiased translucent border?

     
  • Erik

    Erik - 2015-11-20

    And, not too surprisingly as I am sure they use the same internal mechanisms, an svg ellipse has the same artifacts.

    I am thinking of two workarounds:
    1. Make a custom shapes font and skew it with svg. It seems that fonts do not have the pixel halo that shapes do. This would be an ardous task trying to get positions correct, adjusting for baselines and font sizes and ugh.
    2. Render the shape to black on white, then the color I want my shape on white, and use those two to punch out a composite.

     
  • Erik

    Erik - 2015-11-23

    So... before I go working around this... is this a known bug or am I doing something wrong ?

    How can I help GM?

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2015-11-23

      On Mon, 23 Nov 2015, Erik wrote:

      So... before I go working around this... is this a known bug or am I doing something wrong ?

      How can I help GM?

      drawing ellipse on transparent canvas creates unwanted 'halo'

      I am sure that this is a known issue. The problem is that the
      blending is always dealing with two colors (canvas image pixel color
      and pen/drawing color). Even if the image appears to be transparent,
      it still has color (e.g. black), even if it can't be seen after alpha
      composition on top of another image. It is not really possible to
      anti-alias or blend without considering the color of what is being
      drawn on. If the underlying color is transparent, then it should not
      contribute to the computed result. I think that this is what the
      existing math is trying to do.

      If the image is 50% transparent and black, then the result is going to
      be a modulation between the pen color and black, but reducing the
      influence of the black by 50%. But the result still contains black
      which would be unwanted if composited on top of an image of a
      different color.

      The drawing code uses AlphaCompositePixel() in
      magick/alpha_composite.h. In order to help GM, someone would need to
      study AlphaCompositePixel() and determine improved math which solves
      the fringing problem while not breaking other usages. If it does
      break other usages, then a new function is needed to replace
      AlphaCompositePixel() in the render code.

      I have seen some images where drawing was partially done in the
      opacity channel rather than the color channels. This could be a
      solution but makes the resulting image not very usable for other
      purposes.

      Bob

      Bob Friesenhahn
      bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
      GraphicsMagick Maintainer, http://www.GraphicsMagick.org/

       
  • Ben Nadel

    Ben Nadel - 2020-03-06

    I'm just running into this myself. I'm attempting to create intermediary images that contain some "annotations". Then, I was planning to create a composite image of all the "annotation images" on top of the target image. Only, the annotation images all end up with that halo effect on the edges.

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2020-03-06

      On Fri, 6 Mar 2020, Ben Nadel wrote:

      I'm just running into this myself. I'm attempting to create
      intermediary images that contain some "annotations". Then, I was
      planning to create a composite image of all the "annotation images"
      on top of the target image. Only, the annotation images all end up
      with that halo effect on the edges.

      This problem has not been studied or worked on yet. Similar issues
      have been solved in other areas such as when resizing an image, which
      also produced fringing.

      I am not sure if the SVG specification addresses drawing on
      transparent backgrounds.

      Bob

      Bob Friesenhahn
      bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
      GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
      Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

       
  • Ben Nadel

    Ben Nadel - 2020-03-06

    Sounds good :thumbs-up:

     

Log in to post a comment.