How to replicate IrfanView's colordepth reduction using ImageMagick?

234 Views Asked by At

I usually use IrfanView v4.62 to decrease colour depth for PNG images to 4 bits per pixel. But I now need to use ImageMagick v7 because I need to cron a batch job on Linux (CentOS 7.9). IrfanView doesn't run on Linux (except on Wine, which is not feasible for me).

Problem: I'm unable to replicate the results of Irfanview using ImageMagick.

What I did on IrfanView:

  • Image > Decrease Color Depth > 16 Colors (4 BPP) > Use Floyd-Steinberg dithering

What I tried on ImageMagick:

  • magick x.png -depth 4 x-depth4.png
  • magick x.png -colors 16 x-color16.png

None of the ImageMagick options I chose could produce the quality of color-reduced image that IrfanView could. IrfanViews results were "smoother" and closer to the original.

Does anyone know the equivalent options for magick to achieve the results of IrfanView as described?

(The reason for wanting to reduce color depth is to reduce filesize by 10x, more or less.)

Thank you.

Edit: Here are 3 images for comparison:

Original image: dd.png (739KB)

Processed by IrfanView: dd-irfanview-depth4.png (86KB)

Processed by ImageMagick: dd-magick-colors16.png (67KB)

1

There are 1 best solutions below

2
On BEST ANSWER

I think this command produces an even better result than IrfanView - though I would have to question the point of using PNG format for a photo-like image - why not JPEG?

Anyway:

magick input.png -dither FloydSteinberg -colors 16 result.png

enter image description here