bugGNU Octave - Bugs: bug #54309, Internal transparent area of png...

 
 

bug #54309: Internal transparent area of png image is loaded as border color by imread

Submitter:  Tis Veugen <tis>
Submitted:  Fri 13 Jul 2018 06:55:21 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Tis Veugen Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 15 Jul 2018 08:49:58 AM UTC, comment #9: 

You mean in Matlab?
pic attached. Solid heart I'd say


Philip Nienhuis <philipnienhuis>
Group Member
Sat 14 Jul 2018 11:54:54 PM UTC, comment #8: 

Interesting, Matlab does exactly what Octave does.  The IMG data is solid in the center, and you need the Alpha mask in order to get the right image.

@Philip: What happens if you display the IMG only using imshow?


load imgvar.mat
imshow (IMG)


Is it a solid heart or an outlined heart?

Rik <rik5>
Group administrator
Sat 14 Jul 2018 10:21:41 PM UTC, comment #7: 


> Because there is no color associated with pixels in the center of the image (they are transparent) their color channel value really can be anything.


This is incorrect. There is colour associated with the pixels in the centre of the image, and in this case they are red. Those pixels are also transparent which is why your image viewer will show the canvas background (in my case that's a checker board pattern).

Also, note that a pixel does not have to be fully opaque and fully transparent, with png images, there's a range of transparency values.

Carnë Draug <carandraug>
Group Member
Sat 14 Jul 2018 10:17:28 PM UTC, comment #6: 


>  In the read image the internal transparent area is wrongly not transparent, but has the (red) color of the border.


This is not a bug, this is the way it's supposed to work. The transparency of a pixel and the colour value of that pixel are separate things. Even if a pixel is meant to be transparent, it still needs a colour value. You need to read the transparency separately (3rd output argument of imread) and then decide how to display that transparency.

Carnë Draug <carandraug>
Group Member
Sat 14 Jul 2018 08:22:11 PM UTC, comment #5: 

Here you go (ML r2018b prerelease)

(file #44556)

Philip Nienhuis <philipnienhuis>
Group Member
Fri 13 Jul 2018 09:12:27 PM UTC, comment #4: 

But GraphicsMagick is probably applying the alpha layer.

If someone has access to Matlab, can they run


[IMG, MAP, ALPHA] = imread ('hearts_o.png');
save ('imgvar.mat', 'IMG', 'MAP', 'ALPHA');


and then upload the file imgvar.mat?

Rik <rik5>
Group administrator
Fri 13 Jul 2018 08:50:08 PM UTC, comment #3: 

gm display hearts_o.png  works fine, so I assume GM is fine.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 13 Jul 2018 08:45:11 PM UTC, comment #2: 

Confirmed.  The question is whether this is something that the GraphicsMagick libary is doing, or is it something that Octave is doing?

Note that the extra information about the alpha channel is present in the third output argument.


help imread
[IMG, MAP, ALPHA] = imread (FILENAME)


Because there is no color associated with pixels in the center of the image (they are transparent) their color channel value really can be anything.  In this case they were set to red.  If I apply the alpha layer to the image I get the desired result.


octave:2> [I,M,A] = imread ("hearts_o.png");
octave:3> size (I)
ans =

   424   341     3

octave:4> size (A)
ans =

   424   341

octave:5> A2 = repmat (A, [1 1 3]);
octave:6> I2 = I;
octave:7> I2(! A2) = 0;
octave:8> imshow (I2)


Maybe we should change Octave so that if no alpha argument is requested, then the alpha blending is automatically applied to IMG.

I confirmed as well that this is only an issue with images with an alpha channel.  I took the original image and removed the alpha channel using GIMP and it loads correctly.

Adding Carne to the CC list since he understands image issues.



Rik <rik5>
Group administrator
Fri 13 Jul 2018 07:41:49 PM UTC, comment #1: 

Confirmed on linux, octave 4.4.0x, image-2.8.0.

The issue appears to be with imread(). One can plot red component
with (say):

plot (image(40,:,1))

to see the problem.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 13 Jul 2018 06:55:21 PM UTC, original submission:  

I read a png image with imread; the image has a border enclosing an area that has the transparent color.
In the read image the internal transparent area is wrongly not transparent, but has the (red) color of the border.

Tis Veugen <tis>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #44556:  imgvar.mat added by philipnienhuis (7KiB - application/octet-stream)
file #44554:  read_png.m added by tis (98B - application/octet-stream)
file #44555:  hearts_o.png added by tis (4KiB - 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 rik5 (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by tis (Submitted the item)
  • -email is unavailable- added by tis
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 16 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-15 philipnienhuis Attached File- Added imgvar_IMG-mlr2018b.png, #44559
    2018-07-15 rik5 StatusConfirmed Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2018-07-14 rik5 StatusInvalid / Not an Octave Bug Confirmed
        Open/ClosedClosed Open
    2018-07-14 carandraug StatusConfirmed Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2018-07-14 philipnienhuis Attached File- Added imgvar.mat, #44556
    2018-07-13 rik5 StatusNone Confirmed
        Release4.2.1 dev
        Operating SystemMicrosoft Windows Any
        SummaryInternal transparent area of png image is loaded as border color Internal transparent area of png image is loaded as border color by imread
        Carbon-Copy- Added carandraug
    2018-07-13 tis Attached File- Added read_png.m, #44554
        Attached File- Added hearts_o.png, #44555
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code