The input image is color (not grayscale) but with very few colors (<16 colors). The output image must be 8 bits per pixel (not 4 bit per pixel/not 8bit per color/not grayscale) BMP. The converion must be lossless. (unless the colors more than 256)
What ImageMagick parameters should I use to achieve it ?
Thanks!
I have tried some parameters like:
-colors 256
-type Palette or optimize
-depth 8
But they all output a 4 bits per pixel BMP. I want to ensure the output image a 8 bit per pixel BMP.
Any command-line solution other than ImageMagick is welcomed.
I'd suggest NetPBM and specifically its
ppmtobmptool. If we use a command of the following type to create a PPM file with any desired number of colours:we can then examine what
ppmtobmpdoes.So firstly the default, which is to write the smallest possible image given the number of colours present (the same as what ImageMagick would do):
But if we specify
-bpp 8, we get:And if we submit too many colours for a palette image, it aborts with a failed status ($?=1):