Page 1 of 1

mogrify -depth problem

Posted: 2011-03-28T15:23:50-07:00
by neonism
Hi there

I'm having a strange behaviour (or maybe i don't know what i'm doing wrong) in which I try to convert a png image i have from 4bit format to 8bit format

using identify -verbose image.png

Depth: 8/4-bit
Channel depth:
gray: 4-bit

then i use mogrify image.png -depth 8 to change the depth of the image

then i use again identify -verbose image.png to see the results

Depth: 8/4-bit
Channel depth:
gray: 4-bit

but i expected
Depth: 8-bit
Channel depth:
gray: 4-bit

For more info i'm using ImageMagick-6.6.8-10-Q16-windows-x64 version with Windows 7 Ultimate 64

Re: mogrify -depth problem

Posted: 2011-03-28T17:38:13-07:00
by fmw42
then i use mogrify image.png -depth 8 to change the depth of the image
Mogrify does not work on individual images by name, but on whole folders of images. You either need to change your mogrify command syntax or use convert.

convert image.png -depth 8 resultimage.png

Note that depth is depth per channel. If you want an 8-bit palette image use PNG8:

convert image.png PNG8:resultimage.png

mogrify -format png -depth 8 *.png

see
http://www.imagemagick.org/Usage/basics/#cmdline
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/formats/#png

Re: mogrify -depth problem

Posted: 2011-03-29T00:28:04-07:00
by neonism
still not working properly

convert image.png -depth 8 resultimage.png -> resulted in

Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 689x1112+0+0
Resolution: 39.37x39.37
Print size: 17.5006x28.2449
Units: PixelsPerCentimeter
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8/4-bit
Channel depth:
gray: 4-bit

convert image.png PNG8:resultimage.png -> results in

Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 689x1112+0+0
Resolution: 39.37x39.37
Print size: 17.5006x28.2449
Units: PixelsPerCentimeter
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: RGB
Depth: 8/4-bit
Channel depth:
gray: 4-bit

(this one says 8/4 depth but then if i click properties in windows explorer says 8 bits instead of 4, the thing is that i see that the colorpsace changed from Gray to RGB which i don't know if it's correct or not)

mogrify -format png -depth 8 *.png -> results in

Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 689x1112+0+0
Resolution: 39.37x39.37
Print size: 17.5006x28.2449
Units: PixelsPerCentimeter
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8/4-bit
Channel depth:
gray: 4-bit

Re: mogrify -depth problem

Posted: 2011-03-29T01:55:26-07:00
by neonism
update: i tried using -verbose to see what the program is doing

C:\soft\prova>mogrify -verbose -format png -depth 8 *.png
1.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 246KB 0.016u 0:00.016
1.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 229KB 0.219u 0:00.108
2.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 246KB 0.031u 0:00.016
2.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 229KB 0.203u 0:00.108
20f5mhh.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 246KB 0.000u 0:00.000
20f5mhh.png PNG 689x1112 689x1112+0+0 8-bit PseudoClass 16c 229KB 0.219u 0:00.110

the thing is that everytime i write the instruction i get the same results (246kb to 229kb) like if results do not overwrite the originals

i tried it under another computer running windows XP and i got the same results

Re: mogrify -depth problem

Posted: 2011-03-29T09:47:57-07:00
by fmw42
What are you expecting? If you have 4-bit color in 8-bit format, that is the best you can do. You cannot get more colors that your 16 (4-bits) without dithering. All you can do is represent them as 8-bit values with large gaps of missing colors. Perhaps you can explain further what you really are trying to accomplish.

Re: mogrify -depth problem

Posted: 2011-03-29T10:24:46-07:00
by glennrp
PNG8 is 8-bit indexed RGB.

If you want 4-bit grayscale, use the current version (IM-6.6.9)
convert image.png -define PNG:bit-depth=4 -define PNG:color-type=0 image_4bit_gray.png
and hope for the best (PNG color-type 0 is opaque grayscale). This will fail
if you have any pixels that aren't in the 16-bit grayscale palette (#000000, #111111,
..., #ffffff), so be sure to reduce your image to that palette first (I think
you have already done that).

Re: mogrify -depth problem

Posted: 2011-05-20T05:46:57-07:00
by glennrp
As of ImageMagick-6.6.9-10, SVN revision r4475, the PNG encoder respects the -depth setting, even for depths 1, 2, 4.

Before processing the image, coders/png.c reduces all pixels, colormap entries, and the background color in its own copy of the image to the specified bit depth by

1) scaling them to 8 bits using ImageMagick's existing scaling macros
2) replacing the low bits using "left-bit-replication" as described in the PNG specificatio
3) expanding back to the Quantum depth using ImageMagick's existing scaling macros.

Depths not in the PNG specification are handled as a valid depth (anything greater than
8 is treated as 16; 5, 6, and 7 as 8; and 3 as 4).