Page 1 of 1
Imagemagick automatically lowering depth too far.
Posted: 2016-05-11T22:03:41-07:00
by Aroymart
Hello! I've just started using ImageMagick so I appologize if I'm missing something simple.
I'm working on a project that requires indexed pngs with a Bit Depth of 2. I'm creating the images and converting them using
Code: Select all
convert [image location 1] -depth 2 [new image location]
This works perfectly for images with at least 3 colors, however with an image that uses only black and white, it gives it a bit depth of 1. I've confirmed this by running it on several different images and going to
http://regex.info/exif.cgi to check the BitDepth.
My question is, is there any way to force a bit depth of 2 regardless of whether or not there are only 2 colors?
I'm using
Code: Select all
ImageMagick 6.9.3-10 Q16 x86_64 2016-05-04
on the command line.
Thank you in advance
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-11T22:15:18-07:00
by fmw42
What platform? What output image format? Did you use PNG8:output.png?
IM typically tries to output the smallest depth that fits the data?
Did you try using
-define png:bit-depth {depth}
See
http://www.imagemagick.org/Usage/formats/#png_write
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-11T22:23:20-07:00
by Aroymart
I'm using Windows 7 but through Cygwin. I'm outputting as png. I just tried it and that sets the depth to 8. There doesn't seem to be a PNG2: option though.
yea, I'm very limited by the other software.
I just tried
Code: Select all
convert src/gfx/test.png -define png:color-depth=2 -depth 2 src/gfx/test4.png
and it's still bit depth of 1
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-11T23:05:29-07:00
by fmw42
try
Code: Select all
convert src/gfx/test.png -define png:color-depth=2 PNG8:src/gfx/test4.png
But does your input image have more colors that 2? If so, you need to reduce the colors to black and white for example by
Code: Select all
convert src/gfx/test.png -colorspace gray +dither -colors 2 -threshold 50% -define png:color-depth=2 PNG8:src/gfx/test4.png
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-11T23:23:10-07:00
by Aroymart
Thank you for the suggestions
The line
Code: Select all
convert src/gfx/test.png -define png:color-depth=2 PNG8:src/gfx/test4.png
results in a png of bit-depth 8
for images that start with 3-4 colors, converting the image to a bit depth of 2 works. Sometimes it groups greys that are too close together as the same color though so I'll experiment with those options to see if I can make it more strict, Thank you!
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-12T00:15:18-07:00
by fmw42
The PNG developer may have other ideas to suggest. You can also try -monochrome to convert to binary if you have other colors than black and white.
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-12T04:50:22-07:00
by glennrp
Don't use "PNG8:" because that forces a bit-depth of 8. Try this:
Code: Select all
convert test.png -colors 4 \
-define png:color-type=3 \
-define png:bit-depth=2 \
-define png:exclude-chunk=bKGD \
test5.png
(excluding the bKGD to prevent your image from having 5 colors, that won't fit in a 2-bit palette)
Re: Imagemagick automatically lowering depth too far.
Posted: 2016-05-12T09:41:34-07:00
by Aroymart
fmw42 wrote:The PNG developer may have other ideas to suggest.
Oh sorry, I know there are multiple ways to define/talk about bit depth. I and the website are talking about 2 bits per pixel, so up to 4 different colors at once. I'd like to have my images indexed with a bit depth of 2, which works when I feed it 3 or 4 colors.
glennrp wrote:Don't use "PNG8:" because that forces a bit-depth of 8. Try this:
Code: Select all
convert test.png -colors 4 \
-define png:color-type=3 \
-define png:bit-depth=2 \
-define png:exclude-chunk=bKGD \
test5.png
(excluding the bKGD to prevent your image from having 5 colors, that won't fit in a 2-bit palette)
That worked! Thank you so much! I did change one thing though (for future reference if anyone needs anything as specific as this
). With
the resulting image came out negated and gave me the warning
Code: Select all
convert: Wrote palette index exceeding num_palette `src/gfx/music2.png' @ warning/png.c/MagickPNGWarningHandler/1656.
It's probably just me misunderstanding how the input file should have been formatting, but removing it worked so I'm content.
Thank you all very much!