Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. How?

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
geep999
Posts: 17
Joined: 2010-12-10T07:33:21-07:00
Authentication code: 8675308

Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. How?

Post by geep999 »

I'm using a program "Seam Carving GUI" that can save .png files of its masks. The program can also read in masks.
There are 2 types of mask - in appearance they are either green or red images on a transparent background.

Created my own mask using gimp but it isn't recognised properly by the program.
I'd like to use convert to change gimp's image into a usable mask - example from a good mask "identify -verbose" is below.

Tried all manner of convert options but I've had no success, the last attempt being:

Code: Select all

convert -transparent "#000000" -type PaletteMatte mymask.png PNG8:my.PaletteMatte.png
(This is for a red image on a black background).

I'm pretty sure my problem is to do with bit depth and alpha channel.
identify -verbose on a good mask "saved.mask.png" shows:
Depth: 8-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
alpha: 8-bit

But using the above convert command "my.PaletteMatte.png" shows:
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit

Can anybody tell me the parameters to create a "good mask"?
I'm using Version: ImageMagick 6.6.6-9 2011-01-17 Q16 http://www.imagemagick.org

(It has crossed my mind that the program could be creating non-standard .png files that are only readable by itself.
But then I remember that gimp and ImageMagick etc. are quite happy to read and process these files).


Cheers,
Peter

identify -verbose saved.mask.png
Image: saved.mask.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 2599x776+0+0
Resolution: 32.68x33.07
Print size: 79.5288x23.4654
Units: PixelsPerCentimeter
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
alpha: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 0.321528 (0.00126089)
standard deviation: 9.0491 (0.0354867)
kurtosis: 788.09
skewness: 28.1085
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Blue:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Alpha:
min: 0 (0)
max: 255 (1)
mean: 0.312748 (0.00122646)
standard deviation: 8.83258 (0.0346376)
kurtosis: 803.638
skewness: -28.3381
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 63.7522 (0.250009)
standard deviation: 6.32259 (0.0247945)
kurtosis: 217038
skewness: 6150.17
Alpha: none #00000000
Histogram:
2014281: ( 0, 0, 0, 0) #00000000 none
1846: (255, 0, 0,255) #FF0000 red
153: (255, 0, 0,204) #FF0000CC rgba(255,0,0,0.8)
123: (255, 0, 0,251) #FF0000FB rgba(255,0,0,0.984314)
121: (255, 0, 0,254) #FF0000FE rgba(255,0,0,0.996078)
91: (255, 0, 0,253) #FF0000FD rgba(255,0,0,0.992157)
82: (255, 0, 0,245) #FF0000F5 rgba(255,0,0,0.960784)
68: (255, 0, 0,232) #FF0000E8 rgba(255,0,0,0.909804)
59: (255, 0, 0,141) #FF00008D rgba(255,0,0,0.552941)
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 2599x776+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2011-02-28T20:08:42+00:00
date:modify: 2011-02-28T20:08:42+00:00
signature: 481037812242a68ad01f6c06460fb2e98b050593626061067b3ab41362ee74b1
Artifacts:
verbose: true
Tainted: False
Filesize: 9.7KBB
Number pixels: 2.017MB
Pixels per second: 33.61MB
User time: 0.050u
Elapsed time: 0:01.060
Version: ImageMagick 6.6.6-9 2011-01-17 Q16 http://www.imagemagick.org
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. H

Post by fmw42 »

best thing would be to post a link to one of your masks.

in the meantime try the latest version of IM as PNG keeps improving.

try
convert mymask.png -type PaletteMatte PNG8:my.PaletteMatte.png

but the color under the transparent cannot be the same color as the non-transparent regions for PNG8 with transparency. Also PNG8 does not allow anything but binary transparency (on/off), no partial transparency. Your histogram shows partial transparency. If you need antialiasing in the transparency then you need to use PNG32 (and possibly -type truecolormatte)

see other controls at

http://www.imagemagick.org/Usage/formats/#png_formats
http://www.imagemagick.org/Usage/formats/#png_write
geep999
Posts: 17
Joined: 2010-12-10T07:33:21-07:00
Authentication code: 8675308

Re: Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. H

Post by geep999 »

Have installed 6.6.7-10 and read the suggested links. And found that this works OK for me:

Code: Select all

convert -depth 1 -transparent "#000000" mymask.png my.new.png
identify -verbose shows:
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
alpha: 1-bit

In my sample file there was alpha: 8-bit but alpha: 1-bit works OK. Something is a bit odd though, but I'm not very bothered: "Seam Carving GUI" complains repeatedly "QImage::setPixel: Index -65536 out of range". As the results are OK I'm not pursuing this.

So thanks for the pointers, Fred.
Cheers,
Peter
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. H

Post by fmw42 »

convert -depth 1 -transparent "#000000" mymask.png my.new.png

Generally you should put the input image right after convert, with a few exceptions such as with vector images.

convert mymask.png -depth 1 -transparent "#000000" my.new.png

see http://www.imagemagick.org/Usage/basics/#cmdline
geep999
Posts: 17
Joined: 2010-12-10T07:33:21-07:00
Authentication code: 8675308

Re: Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. H

Post by geep999 »

Thanks Fred - noted.
Think I'll need to check a few scripts I have - I don't think I've consistently done that. Haven't noted any problems, however.
Cheers,
Peter
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need Depth 8bit Red/Green/Blue 1-bit, Alpha 8-bit png. H

Post by fmw42 »

For the most part it is backward compatible. It is just a warning that things could go awry in some circumstances.
Post Reply