png24 with IM 6.4.0

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hodge

png24 with IM 6.4.0

Post by hodge »

I need to produce a 24-bit png file (8-bits per color, no alpha) with the "convert" app in ImageMagick 6.4.0. I have tried all of these and more:

$ file in.tif
in.tif: TIFF image data, little-endian
$ convert in.tif out.png
$ file out.png
out.png: PNG image, 303 x 344, 16-bit/color RGB, non-interlaced
$ convert in.tif png24:out.png
$ file out.png
out.png: PNG image, 303 x 344, 8-bit/color RGB, non-interlaced
$ convert in.tif -depth 24 png24:out.png
$ file out.png
out.png: PNG image, 303 x 344, 8-bit/color RGB, non-interlaced
$ convert in.tif -depth 24 out.png
$ file out.png
out.png: PNG image, 303 x 344, 16-bit/color RGB, non-interlaced

It seems that I may need IM 6.5.2 or better to do what I need, but I'm stuck with Fedora 10 at this point and upgrading seems to put me in dependency pergatory. Help please! Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

try

convert in.tif -depth 8 PNG24:out.png
hodge

Re: png24 with IM 6.4.0

Post by hodge »

No dice:

$ convert in.tif -depth 8 png24:out.png
$ file out.png
out.png: PNG image, 303 x 344, 8-bit/color RGB, non-interlaced
$ convert --version
Version: ImageMagick 6.4.0 07/27/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC
hodge

Re: png24 with IM 6.4.0

Post by hodge »

I braved the painful path of upgrading to the latest imageMagick (dependencies, an md5sum rpm issue and finally building from source). Still not working:

$ convert --version
Version: ImageMagick 6.5.4-1 2009-06-30 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC

$ convert in.tif -depth 8 png24:out.png
$ file out.png
out.png: PNG image, 303 x 344, 8-bit/color RGB, non-interlaced
$ convert in.tif -depth 24 png24:out.png
$ file out.png
out.png: PNG image, 303 x 344, 8-bit/color RGB, non-interlaced
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

I think you will need to post your in.tif so it can be examined and used for testing
hodge

Re: png24 with IM 6.4.0

Post by hodge »

Unfortunately, I can't attach files in this forum. Could it be caused by me only having a green color channel (no red or blue colors) in the source tiff image? Have you seen imagemagick create a png24? I was browsing through the code, and it wasn't obvious that it was able to do so.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

hodge wrote:Unfortunately, I can't attach files in this forum. Could it be caused by me only having a green color channel (no red or blue colors) in the source tiff image? Have you seen imagemagick create a png24? I was browsing through the code, and it wasn't obvious that it was able to do so.
You can post your image elsewhere and link to it here. Alternately, send me a copy at my private email address (fmw at alink dot net) and I will look at it.

Not sure what you mean by not having red or blue channels - either it is grayscale or it has red, green and blue channels, but they can be all black.

As far as I can tell, yes it can make 24bit color png. The PNG24: format is supposed to do that. I tried to generate a 16-bit tif image yesterday, but it ended up 16/8. So that was not a fair test of converting it to 24-bit png. That was why I was asking for your image. see http://www.imagemagick.org/Usage/formats/#png_formats.

If you cannot provide it, then reply with the results of:

identify -verbose in.tif
hodge

Re: png24 with IM 6.4.0

Post by hodge »

OK, so I think one issue may be that "file out.png" is not correctly reporting the color depth. "identify -verbose out.png" seems to work better, but it's still reporting that some of my colors are 8-bit, and some are 1-bit.

Perhaps I oversimplified my original objective. In the end, what I'm trying to do is take 3 8-bit grayscale tiff files and composite them together as the red, blue, and green channels of a 24-bit png. I am currently individually converting to each grayscale png to color with the following:
convert toRed.tif -channel gb -threshold 99999999 -type TrueColor red.tif
convert toGreen.tif -channel rb -threshold 99999999 -type TrueColor green.tif
convert toBlue.tif -channel rg -threshold 99999999 -type TrueColor blue.tif

Then I composite them:
composite red.tif -compose plus green.tif -compose plus blue.tif png24:out.png

But I'm not getting a 24-bit color png, identify says it has only 1 bit for blue or whatever color.tif comes last. Sorry if this confuses matters, but I was trying to simplify my original post to make it easy to reproduce.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

try

convert toRed.tif toGreen.tif toBlue.tif -combine PNG24:toColor.png
hodge

Re: png24 with IM 6.4.0

Post by hodge »

That's it exactly. Note that this works with 6.4.0 and 6.5.4.1, but not 6.3.2. I guess the lesson here is not to trust the linux "file" command when it comes to color depths. Stick with "identify -verbose".

Thanks for your help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

hodge wrote:That's it exactly. Note that this works with 6.4.0 and 6.5.4.1, but not 6.3.2. I guess the lesson here is not to trust the linux "file" command when it comes to color depths. Stick with "identify -verbose".

Thanks for your help.

What is the problem with 6.3.2? Is there an error (message)? What do you get from identify -verbose toColor.png?

Perhaps too early a version for PNG24 or it was not working correctly at the time?
hodge

Re: png24 with IM 6.4.0

Post by hodge »

The colors are not combined in the same way. The image looks different.
hodge

Re: png24 with IM 6.4.0

Post by hodge »

It looks like this image is still using a palette instead of truecolor. I'm trying to read this into my java app and I think it's choking on the palette. Maybe I should open a different discussion on how to get an image into a format that java's "BufferedImage" likes. I convert it to a bmp and it seems to like it. I thought png24 was a common enough standard that java would support it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png24 with IM 6.4.0

Post by fmw42 »

Sorry I thought you wanted 8-bits per channel so that 24-bits total color. If you want a palette, then you only get 8-bits total color (256 colors).

convert toRed.tif toGreen.tif toBlue.tif -combine -depth 8 -colors 256 PNG8:toColors3.png

identify -verbose toColors3.png
Image: toColors3.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 304x344+0+0
Resolution: 393.7x393.7
Print size: 0.772162x0.873762
Units: PixelsPerCentimeter
Type: Palette
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit

Channel statistics:
red:
min: 127 (0.498039)
max: 255 (1)
mean: 129.548 (0.50803)
standard deviation: 10.8818 (0.0426737)
kurtosis: 73.384
skewness: 7.9672
green:
min: 0 (0)
max: 255 (1)
mean: 246.014 (0.964762)
standard deviation: 35.8991 (0.140781)
kurtosis: 36.6823
skewness: -6.02006
blue:
min: 0 (0)
max: 255 (1)
mean: 14.1141 (0.0553493)
standard deviation: 51.3506 (0.201375)
kurtosis: 12.7507
skewness: 3.74396
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 97.419 (0.382035)
standard deviation: 104.388 (0.409363)
kurtosis: -1.41785
skewness: 0.434554
Histogram:
48717: (127,253, 0) #7FFD00 rgb(127,253,0)
41343: (128,253, 1) #80FD01 rgb(128,253,1)
6884: (128,253, 0) #80FD00 rgb(128,253,0)
hodge

Re: png24 with IM 6.4.0

Post by hodge »

I am wanting 24 bits total color. I'm just still struggling to get it read by my application. Thanks for your help.
Post Reply