Menu

#263 transparent virtualpixelmethod

v1.0_(example)
closed-invalid
None
2
2014-03-03
2014-02-10
No

When the virtualpixel is transparent for displace operator, Image pixels are transparent and virtual pixels are black. The correct result should have virtual pixels transparent and image pixels showing the image pixels.

2 Attachments

Related

Bugs: #263

Discussion

  • sara shafaei

    sara shafaei - 2014-02-10

    Here is the command:
    gm composite map.bmp bird.bmp -matte -background transparent
    -virtual-pixel constant -displace 100x100 out.png

    map.bmp and bird.bmp are attached

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-11

    I expect that the complaint is about ugly black fringing around the displaced image content. The 'transparent' color is transparent black so it does have a color. I believe the problem is due to how the existing InterpolateViewColor() code (which creates a blended target pixel based on the relative contribution of four source pixels) is functioning. Some other similar algorithms have received changes so that transparent pixels do not contribute any color. This algorithm should have similar updates.

     
  • sara shafaei

    sara shafaei - 2014-02-11

    Actually problem is not the black fringing around image content. There is no image content at all. Did you compare Expected result (CorrectResult.png) and current output (CurrentResult.bmp). I attached them here in this bug report. In the current output all image pixels are transparent and there is no image content at all.
    I will attach them here again:

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-12

    Firefox, GraphicsMagick, and ImageMagick, are displaying your CurrentResult.bmp just fine. Probably it is a problem with some readers not knowing how to read BMPv3 format. Obviously Firefox 26 does but the software SourceForge uses for creating a thumbnail does not.

    Try this (prefix output filename with 'bmp2:') and see if it works better for you:

    ~~~~~~~~~
    gm composite map.bmp bird.bmp -matte -background transparent -virtual-pixel constant -displace 100x100 bmp2:output.bmp
    ~~~~~~~~~~~

    Bob

     
    • sara shafaei

      sara shafaei - 2014-02-12

      You are right. It was something to do with the format. I was using preview on Mac to see the Image. I saved in to png that solved the problem.
      Now, I can see the black fringing around the image. You said this algorithm is going to have update. Just wondering, when you are planning to fix this.

      Thank you so much,
      ~Sara

      On Feb 11, 2014, at 9:20 PM, Bob Friesenhahn bfriesen@users.sf.netamp#98;amp#102;amp#114;amp#105;amp#101;amp#115;amp#101;amp#110;amp#64;amp#117;amp#115;amp#101;amp#114;amp#115;amp#46;amp#115;amp#102;amp#46;amp#110;amp#101;amp#116; wrote:

      Firefox, GraphicsMagick, and ImageMagick, are displaying your CurrentResult.bmp just fine. Probably it is a problem with some readers not knowing how to read BMPv3 format. Obviously Firefox 26 does but the software SourceForge uses for creating a thumbnail does not.

      Try this (prefix output filename with 'bmp2:') and see if it works better for you:

      gm composite map.bmp bird.bmp -matte -background transparent -virtual-pixel constant -displace 100x100 bmp2:output.bmp

      Bob


      [bugs:#263]http://sourceforge.net/p/graphicsmagick/bugs/263/ transparent virtualpixelmethod

      Status: open
      Created: Mon Feb 10, 2014 04:18 PM UTC by sara shafaei
      Last Updated: Tue Feb 11, 2014 03:46 PM UTC
      Owner: Bob Friesenhahn

      When the virtualpixel is transparent for displace operator, Image pixels are transparent and virtual pixels are black. The correct result should have virtual pixels transparent and image pixels showing the image pixels.


      Sent from sourceforge.nethttp://sourceforge.net because you indicated interest in https://sourceforge.net/p/graphicsmagick/bugs/263/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

      The contents of this message, together with any attachments, are intended only for the use of the individual or entity to which they are addressed and may contain information that is confidential and exempt from disclosure. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message, or any attachment, is strictly prohibited. If you have received this message in error, please notify the original sender immediately by telephone or by return E-mail and delete this message, along with any attachments, from your computer. Thank you.

       

      Related

      Bugs: #263

  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-12

    I notice that the GIMP on Linux also reads the BMPv3 output just fine.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-12
    • status: open --> closed-invalid
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-12

    This seems to be a problem with the reader used to look at the BMP output file. Using BMPv2 seems likely to fix the problem with the broken reader. Closing this issue as not actually a bug. We can re-open if there is somehow a bug.

    Thank you very much for helping to educate me on the displace displace algorithm.

     
  • sara shafaei

    sara shafaei - 2014-02-12

    You are right. It was something to do with the format. I was using preview on Mac to see the Image. I saved in to png that solved the problem.
    Now, I can see the black fringing around the image. You said this algorithm is going to have update. Just wondering, when you are planning to fix this.

    Thank you so much,
    ~Sara

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2014-02-12

      On Wed, 12 Feb 2014, sara shafaei wrote:

      You are right. It was something to do with the format. I was using preview on Mac to see the Image. I saved in to png that
      solved the problem.
      Now, I can see the black fringing around the image. You said this algorithm is going to have update. Just wondering, when you
      are planning to fix this.

      I have a demanding day job which has nothing to do with image
      processing. It will get fixed when I have the time and mental energy
      to work on it. Luckily the algorithm is well isolated to just one
      small function.

      Bob

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

       
  • sara shafaei

    sara shafaei - 2014-02-12

    Thank you for your effort. I appreciate it.

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2014-02-17

      I put in a fix for the background color fringing problem. It may not
      be the final solution but the result looks much better with the fix.

       
  • Troy Patteson

    Troy Patteson - 2014-02-25

    Hi Bob,

    The issue with pixel interpolation is similar to the previous issue with image shear/rotation. I have attached a patch to remove the black artefacts generated from images with fully transparent backgrounds that are transformed with an operator requiring pixel interpolation such as displace.

    The approach is to compute the pixel area for each of the four pixels that form the interpolated pixel but use an area of zero for any pixel that is fully transparent as a fully transparent pixel must not contribute colour information regardless of its red, green or blue values. If all pixels are fully transparent then set the red, green and blue colours to zero. Otherwise, sum the percentages of red, green and blue components that make up the interpolated pixel. Percentages are computed as the individual pixel area over the total pixel area.

    I have attached the displaced bird image before and after the interpolation fix. An image compare shows only differences at the edges of the displaced image.

    Cheers,

    Troy Patteson

     
  • Troy Patteson

    Troy Patteson - 2014-02-25

    Oops. I didn't realise you had already fixed this issue. My Bad.

    Cheers,

    Troy Patteson

     
  • Troy Patteson

    Troy Patteson - 2014-02-26

    Hi Bob,

    I had a close look at the changes to InterpolateViewColor() from the head of the mercurial repository and I can see that the patch doesn't fix the issue. Indeed generating the bird displacement image with that version of gm yielded the same image as before the patch. This is what I would expect because setting a fully transparent pixel's primary contribution to zero is the equivalent of treating it as a black pixel which is what was happening in the first place.

    Consider the following example where p[0] is white and not fully transparent, and p[1], [2] and p[3] are fully transparent (assume Q16):

    alpha = 0.95
    beta = 0.90
    
    p[0].red = 65535
    p[0].green = 65535
    p[0].blue = 65535
    p[0].opacity = 65535
    
    p[1].red = 65535
    p[1].green = 65535
    p[1].blue = 65535
    p[1].opacity = 0
    
    p[2].red = 65535
    p[2].green = 65535
    p[2].blue = 65535
    p[2].opacity = 0
    
    p[3].red = 65535
    p[3].green = 65535
    p[3].blue = 65535
    p[3].opacity = 0
    

    Since the only pixel that isn't fully transparent is p[0] you would expected the interpolated pixel to be the colour of p[0] with the opacity interpolated as per the current calculation in the code.

    But calculating the pixel colour yields:

    color->red = (1.0-beta)*(1.0-alpha)*p[0].red
    color->green = (1.0-beta)*(1.0-alpha)*p[0].red
    color->blue = (1.0-beta)*(1.0-alpha)*p[0].red
    

    which equates to

    color->red = 328
    color->green = 328
    color->blue = 328
    

    A very dark grey pixel indeed!

    The solution is to make a pixel's contribution equal to its area divided by the total area of all non-fully transparent pixels. Take a look at the patch I posted above. That patch doesn't have the check for matte that your patch does and isn't as cleanly written but gives the general idea.

    Cheers,

    Troy Patteson

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2014-02-26

      On Wed, 26 Feb 2014, Troy Patteson wrote:

      which equates to

      color->red = 328
      color->green = 328
      color->blue = 328

      A very dark grey pixel indeed!

      Yes, I was not terribly happy with my fix, which is why I said "May
      not be the final solution" in the ChangeLog.

      The solution is to make a pixel's contribution equal to its area divided by the total area of all non-fully transparent
      pixels. Take a look at the patch I posted above. That patch doesn't have the check for matte that your patch does and isn't as
      cleanly written but gives the general idea.

      A patch did not make it through via email and I am not sure how to
      find it. Where can I find your patch?

      Bob

       
  • Troy Patteson

    Troy Patteson - 2014-02-26

    Glad you asked as I just discovered an issue with bracket placement in my patch. Attached is another version. At the very least you will need to add the check for matte which it doesn't include and perhaps there is a better way to format it.

    Cheers,

    Troy

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2014-02-26

      On Wed, 26 Feb 2014, Troy Patteson wrote:

      Glad you asked as I just discovered an issue with bracket placement in my patch. Attached is another version. At the very
      least you will need to add the check for matte which it doesn't include and perhaps there is a better way to format it.

      Ok. I found your patch. I had to go to a second page.

      I will look at your patch tomorrow.

      There is perhaps a bit more jaggies on the edges but without the
      darker fringing.

      Bob

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

       
  • Troy Patteson

    Troy Patteson - 2014-02-26

    The second version of the patch produces a much nicer image. See the attached displaced bird image. There are no black fringes that I can seen now.

    Cheers,
    Troy

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-02-27

    I replaced my temporary implementation with Troy's patch plus improvements to deal with when the image does not support transparency or the opacity channel contains something else such as Black. The results look really stellar now.

     
  • sara shafaei

    sara shafaei - 2014-03-03

    Thanks Troy and Bob! I tried the new code and results are gorgeous!
    Thanks again!

     

Log in to post a comment.

MongoDB Logo MongoDB