Problems Creating 4-Bit Grayscale PNGs

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
takeshita_kenji
Posts: 2
Joined: 2011-04-10T10:38:30-07:00
Authentication code: 8675308

Problems Creating 4-Bit Grayscale PNGs

Post by takeshita_kenji »

I work a lot with 4-bit grayscale PNGs, but I've noticed this odd behavior that I don't see with any other bit depths. Here are the results of the following commands:
  1. convert -size 300x300 xc:white -draw 'line 0,0,300,300' -type Grayscale -depth 8 line8.png
    Image
  2. convert -size 300x300 xc:white -draw 'line 0,0,300,300' -type Grayscale -depth 4 line4.png
    Image
  3. convert -size 300x300 xc:white -draw 'line 0,0,300,300' -type Grayscale -depth 2 line2.png
    Image
  4. convert -size 300x300 xc:white -draw 'line 0,0,300,300' -type Grayscale -depth 1 line1.png
    Image
Here's some version information:

Code: Select all

% convert -version        
Version: ImageMagick 6.6.7-6 2011-03-10 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP  HDRI 

% libpng-config  --version
1.4.5
What in the world is happening with the 4-bit grayscale image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems Creating 4-Bit Grayscale PNGs

Post by fmw42 »

I could be wrong but I don't think IM PNG supports depth 4 per se. I suspect you need to specify -colors 16 or use -define png:color-type={type}. But please note that IM PNG has undergone quite extensive changes and improvements over time and you would be best to upgrade to the latest release. You can see all the changes from the changelog at http://www.imagemagick.org/script/changelog.php. Also please review the limitations and parameters for controlling PNG at http://www.imagemagick.org/Usage/formats/#png_formats and http://www.imagemagick.org/Usage/formats/#png_write

Your command

convert -size 300x300 xc:white -draw 'line 0,0,300,300' -type Grayscale -depth 4 line4.png

works perfectly fine to make an image like the others on my IM 6.6.9.4 Q16 Mac OSX Tiger.

the verbose statistics are:

Code: Select all

Image: line4.png
  Format: PNG (Portable Network Graphics)
  Class: PseudoClass
  Geometry: 300x300+0+0
  Resolution: 72x72
  Print size: 4.16667x4.16667
  Units: Undefined
  Type: Grayscale
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8/4-bit
  Channel depth:
    gray: 4-bit
  Channel statistics:
    Gray:
      min: 0 (0)
      max: 255 (1)
      mean: 254.037 (0.996224)
      standard deviation: 14.7561 (0.0578671)
      kurtosis: 289.814
      skewness: -17.0163
  Histogram:
       300: (  0,  0,  0) #000000 black
       598: (238,238,238) #EEEEEE gray(238,238,238)
     89102: (255,255,255) #FFFFFF white
  Colormap: 16
         0: (  0,  0,  0) #000000 black
         1: ( 17, 17, 17) #111111 gray(17,17,17)
         2: ( 34, 34, 34) #222222 gray(34,34,34)
         3: ( 51, 51, 51) #333333 grey20
         4: ( 68, 68, 68) #444444 gray(68,68,68)
         5: ( 85, 85, 85) #555555 gray(85,85,85)
         6: (102,102,102) #666666 grey40
         7: (119,119,119) #777777 gray(119,119,119)
         8: (136,136,136) #888888 gray(136,136,136)
         9: (153,153,153) #999999 grey60
        10: (170,170,170) #AAAAAA gray(170,170,170)
        11: (187,187,187) #BBBBBB gray(187,187,187)
        12: (204,204,204) #CCCCCC grey80
        13: (221,221,221) #DDDDDD gray(221,221,221)
        14: (238,238,238) #EEEEEE gray(238,238,238)
        15: (255,255,255) #FFFFFF white
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Problems Creating 4-Bit Grayscale PNGs

Post by glennrp »

IM-6.6.9-4 works for me but IM-6.6.9-3 exhibited the problem.
takeshita_kenji
Posts: 2
Joined: 2011-04-10T10:38:30-07:00
Authentication code: 8675308

Re: Problems Creating 4-Bit Grayscale PNGs

Post by takeshita_kenji »

Well, it looks like the latest Gentoo currently has is 6.6.8-5, so I'll be stuck for a little while. Thanks for the help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems Creating 4-Bit Grayscale PNGs

Post by fmw42 »

try -define png:color-type={type} http://www.imagemagick.org/Usage/formats/#png_write

and see if that helps.
Post Reply