1

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)

cakepuller
  • 13
  • 3
  • Maybe you can add an input and corresponding output image from Irfanview to demonstrate the quality and effect you want to achieve. – Mark Setchell May 03 '23 at 12:14
  • 1
    Find an article that explains Irfan's algorithm. Then perhaps it can be reproduced. Reverse engineering from your description is not possible. – fmw42 May 03 '23 at 15:04
  • @MarkSetchell, Thanks for the reminder. Images added for clarity. – cakepuller May 04 '23 at 08:20

1 Answers1

1

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

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Oh my, thanks a bunch for this. I had tried using the `-dither` option, but I found that it didn't have any effect and was surprised to see your result. I did something like `magick dd.png -colors 16 -dither Floyd-Steinberg result.png`. Turns out the order of the options were significant! Sorry, I'm new user of ImageMagick. Thanks again! (Why png and not jpg? Well reducing number of colors to 16 in png, I've found, gives a smaller filesize compared to jpg. And the photo I used above is only an example. Most of the images I'll be processing are mainly screenshots of a desktop app.) – cakepuller May 04 '23 at 09:45
  • Doh! I stand corrected (somewhat) in my comment above about PNG vs JPG filesizes. 16-color PNG filesize can be larger than JPG, provided the 'quality' of the JPG is about '80' or less (100 being best quality). Anyway, I need to use PNG cos I'm converting existing PNG's which are referenced from some app, and I can't change the file extension to .jpg. – cakepuller May 04 '23 at 10:22