converting 16-bit grayscale to 8-bit

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
taranaki

converting 16-bit grayscale to 8-bit

Post by taranaki »

I'm trying to convert a 16-bit grayscale .tif image (intensity min, max: 0, 4095) down to an 8-bit grayscale .tif (or .png), but naively using -depth 8 isn't working and results in an image with too much missing information.

For example:

Orig.tif has up to 4095 unique color values.

Code: Select all

convert orig.tif -fx 'intensity/16' dithered.tif
--> creates a 16-bit version of orig.tif that looks very close to the original, but only has 256 unique color values. This is what I want, but with 8-bit quality.

Code: Select all

convert orig.tif -depth 8 new.tif
--> poorly dithered 8-bit version. :(

I've tried a lot of things with the same result. The part that gives me some concern that this may be a bug is that when I try to convert the dithered.tif using -depth 8 it is the same as out.tif.

Any assistance would be greatly appreciated!
~Cameron

The images:
http://dl.dropbox.com/u/222088/orig.tif
http://dl.dropbox.com/u/222088/dithered.tif
http://dl.dropbox.com/u/222088/out.tif

Version: ImageMagick 6.5.8-2 2010-02-22 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Features: HDRI OpenMP
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: converting 16-bit grayscale to 8-bit

Post by magick »

Try
  • convert orig.tif -evaluate multiply 16 -depth 8 orig-8.tif
taranaki

Re: converting 16-bit grayscale to 8-bit

Post by taranaki »

This works! Thank you.
andrew

Re: converting 16-bit grayscale to 8-bit

Post by andrew »

What is the significance of

Code: Select all

-evaluate multiply 16
.. is 16 arbitrary?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting 16-bit grayscale to 8-bit

Post by snibgo »

[quote]Orig.tif has up to 4095 unique color values.[quote]

Multiplying by 16 takes the maximum value (white) to 65520, which isn't far from the maximum 16-bit quantum 65525.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting 16-bit grayscale to 8-bit

Post by fmw42 »

you could use -auto-level -depth 8 which would stretch your original image to full dynamic range if that is what you want so that your 8-bit image ranged from 0 to 255.
Post Reply