comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Creating Transparent PNG Images
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Creating Transparent PNG Images [message #68440] Sun, 25 October 2009 09:32
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Greg writes:

> That looks like a colour profile problem. I think your original is
> sRGB, and IDL is probably ignoring that and rewriting without
> specifying a profile. I'm not sure why Photoshop displays them the
> same - I'd expect it to handle the profile properly - but perhaps it's
> not common to have a profile in a 4-channel png.

Well, the problem turned out NOT to be a color profile
problem, thank goodness. But it was a metadata problem.
Thanks to someone who knows about these things for pointing
this out to me in a private e-mail.

I have learned quite a lot more about PNG files in the
past couple of days than I had planned to learn. :-)

First of all, it is possible to include all kinds of
metadata in PNG files. I've also learned that this
metadata is almost completely non-standard, so that is
is *extremely* difficult, if not impossible, to write
a PNG file reader that can preserve the metadata. The
IDL PNG reader, as you might imagine, does not even
try. (This is what I would do, too, if I were writing
a PNG reader.)

The example.png file that I downloaded from the Internet
contains a gAMA metadata tag. This tag indicates the "gamma"
value that should be used in transferring the image data
to the display. My Firefox and Internet Explorer browsers
read that data and do the transfer correctly.

The test.png file I created in IDL from the example.png file
does not include this gAMA tag in the test.png file. It does,
however, write the image data correctly. Thus, my browsers
render this file in darker colors than the previous file, since
there is no gamma correction being made.

To be certain this was the explanation. I downloaded a program
named TweakPNG that allowed me to examine the metadata chucks
in these PNG files.

http://entropymine.com/jason/tweakpng/

I exported the gAMA chunk from example.png and then imported that
chunk into test.png. Low and behold, the test.png file now renders
*exactly* like example.png in my browser!

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Creating Transparent PNG Images [message #68441 is a reply to message #68440] Sat, 24 October 2009 10:13 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
That looks like a colour profile problem. I think your original is
sRGB, and IDL is probably ignoring that and rewriting without
specifying a profile. I'm not sure why Photoshop displays them the
same - I'd expect it to handle the profile properly - but perhaps it's
not common to have a profile in a 4-channel png.

regards,
Greg
Re: Creating Transparent PNG Images [message #68442 is a reply to message #68441] Sat, 24 October 2009 09:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> Devin White writes:
>
>> You can write out transparent 24-bit PNGs by supplying a 4-channel
>> array to WRITE_PNG (4 x samples x lines). The first three channels
>> are RGB, the fourth is the alpha channel. Fully visible pixels should
>> have their corresponding alpha channel elements set to 255,
>> transparent pixels should have theirs set to 0.
>
> OK, well, then the documentation REALLY needs to be improved!
>
> But there is still a problem. Consider the transparent PNG
> image you find here:
>
> http://www.dfanning.com/ip_tips/example.png
>
> I tried this:
>
> IDL> image = read_png('example.png')
> IDL> help, image
> IMAGE BYTE = Array[4, 162, 150]
> IDL> write_png, 'test.png', image
>
> Then, I opened both example.png and test.png in my
> browser (FireFox). They appear to be two different
> images! The test.png file appears in MUCH darker colors.
>
> Any ideas on what this could be about?

The mystery deepens. When I look at these two images in
Photoshop, they appear to be identical, and look much more
like the image I created in IDL then the image I downloaded
from the Internet. And yet, the *data* in the two images
appears to be identical:

IDL> image = read_png('example.png')
IDL> img = read_png('test.png')
IDL> Print, Total(image - img)
0.000000

Even Internet Explorer displays the two images differently.

Very strange. :-(

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Creating Transparent PNG Images [message #68443 is a reply to message #68442] Sat, 24 October 2009 07:59 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Devin White writes:

> You can write out transparent 24-bit PNGs by supplying a 4-channel
> array to WRITE_PNG (4 x samples x lines). The first three channels
> are RGB, the fourth is the alpha channel. Fully visible pixels should
> have their corresponding alpha channel elements set to 255,
> transparent pixels should have theirs set to 0.

OK, well, then the documentation REALLY needs to be improved!

But there is still a problem. Consider the transparent PNG
image you find here:

http://www.dfanning.com/ip_tips/example.png

I tried this:

IDL> image = read_png('example.png')
IDL> help, image
IMAGE BYTE = Array[4, 162, 150]
IDL> write_png, 'test.png', image

Then, I opened both example.png and test.png in my
browser (FireFox). They appear to be two different
images! The test.png file appears in MUCH darker colors.

Any ideas on what this could be about?

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Creating Transparent PNG Images [message #68444 is a reply to message #68443] Sat, 24 October 2009 05:33 Go to previous message
devin.white is currently offline  devin.white
Messages: 50
Registered: March 2007
Member
You can write out transparent 24-bit PNGs by supplying a 4-channel
array to WRITE_PNG (4 x samples x lines). The first three channels
are RGB, the fourth is the alpha channel. Fully visible pixels should
have their corresponding alpha channel elements set to 255,
transparent pixels should have theirs set to 0.


On Oct 23, 2:53 pm, David Fanning <n...@dfanning.com> wrote:
> Folks,
>
> I have a question about transparent PNG images. If you
> go somewhere on the Internet and look for a transparent
> PNG image, you will typically download an image that
> has a "4" in one of its dimensions. One could think
> of this as a "typical" 24-bit or true-color image with
> an extra alpha channel. In IDL you have to go to some
> effort to display such an image correctly:
>
>   http://www.dfanning.com/ip_tips/transparentpng.html
>
> Now, for reasons that are obscure and don't have much
> to do with IDL, I need to create such a PNG image from
> within a piece of IDL code. Unfortunately, it doesn't
> look like WRITE_PNG is up to the job.
>
> I can easily create a 24-bit true-color image. But this
> doesn't allow me to use the TRANSPARENT keyword. The only
> way to make a transparent PNG is to have an 8-bit byte
> image and RGB color vectors.
>
> Am I missing something here in the documentation? Or, if
> not, does anyone have a favorite method for creating
> a true-color PNG file with an alpha channel? (I am
> afraid this is a firm requirement for downstream
> software to work correctly.)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Creating Transparent PNG Images [message #68449 is a reply to message #68444] Fri, 23 October 2009 13:05 Go to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
ImageMagick?

On Oct 23, 1:53 pm, David Fanning <n...@dfanning.com> wrote:
> Folks,
> <snip>
> not, does anyone have a favorite method for creating
> a true-color PNG file with an alpha channel? (I am
> afraid this is a firm requirement for downstream
> software to work correctly.)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Creating Transparent PNG Images [message #68450 is a reply to message #68449] Fri, 23 October 2009 12:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

Just a note to say that the IDL documentation says that
it supports version 1.2.7 of the PNG library. Since this
version was released sometime in the latter half of 2004,
I am certain this CAN'T be right. Or, can it? :-(

The current version is 1.2.40, the final release, apparently
in the 1.2 series. Maybe with version 1.3 IDL could put this
library on its fix-it list. At least I would feel that some
part of my maintenance dollars was well spent if they did so.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Wow! Value_Locate
Next Topic: For loop

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:53:39 PDT 2025

Total time taken to generate the page: 0.00659 seconds