From what I've read so far, it looks like it is not possible to create 8-bit indexed grayscale PNG's with 1-bit alpha channels (e.g. http://en.wikipedia.org/wiki/Portable_N ... olor_depth). Does anyone know whether it's possible to "fake" this by either create indexed grayscale images where one pixel value (e.g. "black") is transparent? Or by specifying that one of the palette values is fully transparent?
My goal is to get from:
+ +
8-bit Grayscale + 1-bit transparency mask + 8-bit RGB color-lookup table (The actual images I'm working with are PGM and TIF files, but I converted them to PNG's to post above)
To:
8-bit Indexed PNG with some fully transparent parts.
I added a checkerboard to make it easier to see transparent parts. The above PNG is close to what I am trying to produce-- I would like to get something that is 8-bit + a palette and or alpha mask, rather than an RGB image. The problem is that when adding the mask the image is converted from grayscale + alpha channel to an 24-bit RGB image which takes a relatively long time.
Any Ideas? Any suggestions would be greatly appreciated.
Thanks!
Keith
-----------------------------------
Edit: Added example images
-----------------------------------
Possible to fake indexed grayscale PNG's with alpha-mask?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
try this test
create grayscale gradient:
convert -size 100x100 gradient: grad100.png
create square mask:
convert -size 50x50 xc:black -bordercolor white -border 25 mask.png
composite to make center square transparent:
convert grad100.png mask.png -compose copy_opacity -composite -type PaletteMatte tmp1.png
look at channels:
identify -verbose tmp1.png
Image: tmp3.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 100x100+0+0
Resolution: 72x72
Print size: 1.38889x1.38889
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: RGB
Depth: 16-bit
Channel depth:
gray: 16-bit
alpha: 1-bit
Channel statistics:
gray:
min: 662 (0.0101015)
max: 65535 (1)
mean: 32773.1 (0.500085)
standard deviation: 19104.1 (0.29151)
kurtosis: -1.20087
skewness: 0.00181054
alpha:
min: 0 (0)
max: 65535 (1)
mean: 49151.2 (0.75)
standard deviation: 28377.5 (0.433013)
kurtosis: -0.666667
skewness: 1.1547
overlay over checkerboard to see where transparent:
convert -size 100x100 pattern:checkerboard tmp3.png -compose over -composite tmp2.png
if you are on 16-bit IM and want 8-bit image, then use:
convert grad100.png mask.png -compose copy_opacity -composite -depth 8 -type PaletteMatte tmp1.png
see -depth and -type at http://www.imagemagick.org/script/comma ... ptions.php
create grayscale gradient:
convert -size 100x100 gradient: grad100.png
create square mask:
convert -size 50x50 xc:black -bordercolor white -border 25 mask.png
composite to make center square transparent:
convert grad100.png mask.png -compose copy_opacity -composite -type PaletteMatte tmp1.png
look at channels:
identify -verbose tmp1.png
Image: tmp3.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 100x100+0+0
Resolution: 72x72
Print size: 1.38889x1.38889
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: RGB
Depth: 16-bit
Channel depth:
gray: 16-bit
alpha: 1-bit
Channel statistics:
gray:
min: 662 (0.0101015)
max: 65535 (1)
mean: 32773.1 (0.500085)
standard deviation: 19104.1 (0.29151)
kurtosis: -1.20087
skewness: 0.00181054
alpha:
min: 0 (0)
max: 65535 (1)
mean: 49151.2 (0.75)
standard deviation: 28377.5 (0.433013)
kurtosis: -0.666667
skewness: 1.1547
overlay over checkerboard to see where transparent:
convert -size 100x100 pattern:checkerboard tmp3.png -compose over -composite tmp2.png
if you are on 16-bit IM and want 8-bit image, then use:
convert grad100.png mask.png -compose copy_opacity -composite -depth 8 -type PaletteMatte tmp1.png
see -depth and -type at http://www.imagemagick.org/script/comma ... ptions.php
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
Hi fmw,
Thanks for the reply. That is close to what I'm doing now except that I also apply a color lookup table, e.g.
Which results in:
The problem is that I want to store the image as as grayscale, using the color-lookup table as it's index. The image only actually has at most 256 colors (+ an alpha channel). When IM applies the color-table, however, it produces a 24-bit RGB image with ~16 million possible colors.
Thanks for the reply. That is close to what I'm doing now except that I also apply a color lookup table, e.g.
Code: Select all
convert grad100.png mask.png -compose copy_opacity -composite -depth 8 -type PaletteMatte ctable.png -clut tmp.png
Code: Select all
Image: tmp.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 100x100+0+0
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 1-bit
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
I don't believe that IM can store color look-up tables in the pseudocolor image type (header). But you had better get confirmation from Anthony or Magick.pwnedd wrote:Hi fmw,
Thanks for the reply. That is close to what I'm doing now except that I also apply a color lookup table, e.g.
Which results in:Code: Select all
convert grad100.png mask.png -compose copy_opacity -composite -depth 8 -type PaletteMatte ctable.png -clut tmp.png
The problem is that I want to store the image as as grayscale, using the color-lookup table as it's index. The image only actually has at most 256 colors (+ an alpha channel). When IM applies the color-table, however, it produces a 24-bit RGB image with ~16 million possible colors.Code: Select all
Image: tmp.png Format: PNG (Portable Network Graphics) Class: DirectClass Geometry: 100x100+0+0 Type: PaletteMatte Endianess: Undefined Colorspace: RGB Depth: 8-bit Channel depth: Red: 8-bit Green: 8-bit Blue: 8-bit Alpha: 1-bit
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
The color lookup (-clut) can not only substitute colors byt transparencys too.
It is just a little trickier as you need to tell IM which image is the grayscale image
(and thus what you are trying to do), and that you also want to work with transparency.
See the examples at
http://www.imagemagick.org/Usage/colors/#clut_rgba
ADDENDUM: sorry mistake in example, fixed no but may take a day to appear.
Replace +alpha off with -alpha off in that last command. or wait a day or so.
So create your blue gradient replacement color image, then replace the first pixel (black replacment color) with a transparent color, and save it for use by your -clut replacement commands.
It is just a little trickier as you need to tell IM which image is the grayscale image
(and thus what you are trying to do), and that you also want to work with transparency.
See the examples at
http://www.imagemagick.org/Usage/colors/#clut_rgba
ADDENDUM: sorry mistake in example, fixed no but may take a day to appear.
Replace +alpha off with -alpha off in that last command. or wait a day or so.
So create your blue gradient replacement color image, then replace the first pixel (black replacment color) with a transparent color, and save it for use by your -clut replacement commands.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
Hi Anthony, thanks for the reply.
I'm still a bit unclear about a couple things:
1. How should I replace the lookup table transparent pixel? Should I specify that the black pixel is transparent via it's alpha channel?
Or specify the transparent color to use?
Or something else?
2. More importantly, would the resulting image be any different than if I had used the unmodified gradient as a color lookup table, and -compose copy_opacity to specify the transparent pixels?
My ultimate goal is to try and speed up the process of generating an a 256-color + binary transparent (or 255 color + binary transparent) image from an 8-bit grayscale image, a 1x256 color lookup table and a binary mask. Right now the process works well, except that the color-lookup table step takes a lot of time.
Any ideas?
I'm still a bit unclear about a couple things:
1. How should I replace the lookup table transparent pixel? Should I specify that the black pixel is transparent via it's alpha channel?
Code: Select all
convert ctable.png -transparent black ctable_transparent.png
Code: Select all
convert ctable.png -transparent-color black ctable_transparent.png
2. More importantly, would the resulting image be any different than if I had used the unmodified gradient as a color lookup table, and -compose copy_opacity to specify the transparent pixels?
My ultimate goal is to try and speed up the process of generating an a 256-color + binary transparent (or 255 color + binary transparent) image from an 8-bit grayscale image, a 1x256 color lookup table and a binary mask. Right now the process works well, except that the color-lookup table step takes a lot of time.
Any ideas?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Possible to fake indexed grayscale PNG's with alpha-mask?
use -transparent to replace the color that would be assigned black.
Or just -draw point the none color into location 0
Or just -draw point the none color into location 0
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/