Reducing color depths

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
drscience

Reducing color depths

Post by drscience »

I need to convert an image with 24 bit color to 18 bit color and, just to make things more difficult, I need this conversion to not be dithered.

I looked through the documentation and I just can't figure out how to do this (assuming it can be done).

I searched through the old posts and found this thread that I thought was just what I was looking for, so I tried this:

Code: Select all

convert image1.bmp -fx 'p/4' -fx 'p*4' image2.bmp
The output I got didn't look any different (my test image was a 24bit gradient, so it should have been obvious). Just to be sure, I tried reducing the color depth much further (3 bit/channel color!) and it was still unchanged.

If somebody could explain how/whether this can be done with Image Magick I would be extremely grateful. I'd rather not spend the time writing a program to do this myself.
drscience

Re: Reducing color depths

Post by drscience »

Okay, nevermind, the above commands do indeed work for what I needed. I don't know why I thought they didn't yesterday. Thanks anyways though :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Reducing color depths

Post by anthony »

You can also use -fx 'int(u*MaxRGB/4)*4/MaxRGB'
The MaxRGB means use the compiled depth of the image. if you want 6 bit use
256 for that value. EG -fx 'int(u*64)/64'

OR you can use faster -evaluate function
-evaluate multiply .25 -evaluate multiply 4
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply