bugGNU Octave - Bugs: bug #36820, imread doesn't consider opacity in...

 
 

bug #36820: imread doesn't consider opacity in Magick::BilevelType, Patch included

Submitted by:  Andreas Weber <andy1978>
Submitted on:  Tue 10 Jul 2012 08:37:48 AM UTC  
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Andreas Weber Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 02 Aug 2013 06:22:44 PM UTC, comment #4: 

I found a method to access the original image type as reported by libpng (the library that GraphicsMagick uses for reading png files). I believe that is fixed with cset 73a3c1580974.

Carnë Draug <carandraug>
Project Member
Tue 30 Jul 2013 12:07:57 PM UTC, comment #3: 

I have fixed part of this problem. With cset 95055b814d35 it now reads the alpha channel correctly.

However, the actual image cannot be a MxNx3 matrix because the image is not a RGB image. Even Matlab documentation says that a grayscale image should be MxNx1 so I don't know why it's returning something different.

As GraphicsMagick reports the image as Bilevel, we must return a matrix of size MxN or pick some other strategy.

Should this bug be closed?

Carnë Draug <carandraug>
Project Member
Wed 11 Jul 2012 08:47:42 AM UTC, comment #2: 

This is the output of matlab:

>> [img,map,alpha]=imread('rect.png');
> size(img)
ans =   600   800     3

> size(map)
ans =     0     0

> size(alpha)
ans = 600   800

> mean(img(:))
ans = 0

mean(alpha(:))
ans = 5.66368125

> min(alpha(:))
ans = 0

> max(alpha(:))
ans = 255

  • In contrast to octave, matlab returns a 600x800x3 (RGB) matrix instead of a 600x800x1 graylevel
  • alpha channel is size 600x800 and corresponds to the image opacity but is "inverted" to graphicsmagick: 0=transparent, 255=opaque. Therefore mean(alpha)=255-249.34=5.66

btw, the original image was created with inkscape and then downscaled.

Andreas Weber <andy1978>
Project Member
Wed 11 Jul 2012 08:00:09 AM UTC, comment #1: 

I don't think it's that easy. The image rect.png was probably created with MS-Paint and has 1-bit gray-depth and 8-bit opacity-depth:

gm identify -verbose rect.png
Image: rect.png
  Format: PNG (Portable Network Graphics)
  Geometry: 800x600
  Class: DirectClass
  Type: bilevel
  Depth: 1 bits-per-pixel component
  Channel Depths:
    Gray:     1 bits
    Opacity:  8 bits
  Channel Statistics:
    Gray:
      Minimum:                     0.00 (0.0000)
      Maximum:                     0.00 (0.0000)
      Mean:                        0.00 (0.0000)
      Standard Deviation:          0.00 (0.0000)
    Opacity:
      Minimum:                     0.00 (0.0000)
      Maximum:                   255.00 (1.0000)
      Mean:                      249.34 (0.9778)
      Standard Deviation:         35.38 (0.1387)
  Opacity: (  0,  0,  0,255)          #000000FF

So I think the image (rectangles, A-D) seen with gimp or any other viewer like eog is only in the alpha channel. Nevertheless

[img,map,alpha]=imread("rect.png");

Should the return the "seen image" in var alpha but

>size(alpha)
ans =
   0   0

I will create some PNG test-images with gimp and MS-Paint for the different image types (RGB, grayscale,bilevel, with or without alpha channel), write some test-scripts and suggest a patch the next week.

greetings, Andy

Andreas Weber <andy1978>
Project Member
Tue 10 Jul 2012 08:37:48 AM UTC, original submission:  

$hg id
c3fd61c59e9c+ tip

I've attached an image "rect.png" of type Magick::BilevelType. When imread in octave, the return value is empty(all zero):

    octave:1> pic=imread("rect.png");
    warning: your version of GraphicsMagick limits images to 16 bits per pixel
    octave:2> min(pic(:))
    ans = 0
    octave:3> max(pic(:))
    ans = 0
    octave:4> imfinfo("rect.png")
    ans =

      scalar structure containing the fields:

        Filename = /home/andy/Holografie/doc/Experimente/ShowHologramFromPNG/rect.png
        FileModDate = 26-Mar-2012 17:03:18
        FileSize =  9053
        Height =  600
        Width =  800
        BitDepth =  8
        Format = PNG
        LongFormat = Portable Network Graphics
        XResolution =  35.430
        YResolution =  35.430
        TotalColors =  1
        TileName =
        AnimationDelay = 0
        AnimationIterations = 0
        ByteOrder = undefined
        Gamma =  0.45455
        Matte =  1
        ModulusDepth =  8
        Quality =  75
        QuantizeColors =  256
        ResolutionUnits = undefined
        ColorType = grayscale
        View =

output of gm identify

   $gm identify rect.png
    rect.png PNG 800x600+0+0 DirectClass 8-bit 8.8K 0.000u 0:01

In _magick_read_.cc:220 there is a switch for BilevelType and GrayscaleType. Afterwards, the red channel of PixelPacket is read but it looks to me taht instead opacity should be used (red is always zero) when type==BilevelType. The attached patch solves my problem but I'm not really sure about the side effects.

Perhaps we can include some small sample images of various types and run some tests against them?

Andy

Andreas Weber <andy1978>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #26174:  rect.png added by andy1978 (9KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by andy1978 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-08-02 carandraug StatusNone => Fixed
        Open/ClosedOpen => Closed
    2012-07-10 andy1978 Attached File- => Added rect.png, #26174
        Attached File- => Added magick_read_BilevelType_opacity.patch, #26175

    Back to the top


    Powered by Savane 3.5