How to convert 11 bit image (16 bit tiff) to 8 bit image?
Posted: 2013-09-11T14:23:54-07:00
I have tens of thousands of grayscale, 11-bit images that are stored as 16-bit tiffs:
They were captured using only 11 bits of depth though (e.g., they are "black" and histogram output shows min: 84 and max: 2036). (For an example, https://www.dropbox.com/s/tjfz1c93q35kuho/test1.tif).
These need to be converted to 8-bit depth images (i.e., -depth 8 ); however, because IM treats the image as having a 16-bit depth, the output is quite off. It seems that I can correct this using -auto-level (or I guess even just level) to first scale up to 16 bits before doing -depth 8, but it's substantially slower, especially where processing is measured in days:
From reading through these forums and the documentation, it appears that -depth scales the input image (as one would expect), so if I could tell IM that the data is actually 11 bits, the scaling to 8 would be correct, I believe. Despite hours of searching though, I can't find a way to do this. I have tried numerous things, including the most obvious:
This doesn't work, and the documentation implies that you can only use depth like this on raw images.
Is there a way to do this (e.g., forcing IM to treat the input as 11 bits or use level to scale directly to 8 bits and then change output file bit depth without scaling)? I'm new to IM, so my apologies if this is something simple that I've just managed to miss.
This is on OS X 10.8.4 with IM:
And I'm not sure that it matters, but the full command I'm running is:
convert test1.tif -auto-level -depth 8 -shave 0x36 -crop 5x3+10+0@ +repage +adjoin -rotate 90 out_imgs/test_5x3_ad_1_%02d.jpg
(To maximize # of component images that are exactly 696x520, since there doesn't appear to be a way to automatically tile like this.)
Any other random performance tips would be greatly appreciated as well. I've already switched to using jpeg-turbo.
Thanks!
Code: Select all
$ identify test1.tif
test1.tif TIFF 2560x2160 2560x2160+0+0 16-bit Grayscale Gray 11.13MB 0.000u 0:00.009
These need to be converted to 8-bit depth images (i.e., -depth 8 ); however, because IM treats the image as having a 16-bit depth, the output is quite off. It seems that I can correct this using -auto-level (or I guess even just level) to first scale up to 16 bits before doing -depth 8, but it's substantially slower, especially where processing is measured in days:
Code: Select all
$ convert -bench 100 -quiet test1.tif -depth 8 test1_8.tif
Performance[1]: 100i 12.788ips 1.000e 7.820u 0:07.820
$ convert -bench 100 -quiet test1.tif -auto-level -depth 8 test1_8.tif
Performance[1]: 100i 4.188ips 1.000e 23.860u 0:23.880
$ convert -bench 100 -quiet test1.tif -level 0%,3.125% -depth 8 test1_8l.tif
Performance[1]: 100i 5.181ips 1.000e 19.270u 0:19.300
Code: Select all
$ convert -depth 11 test1.tif -depth 8 test1_8.tif
Is there a way to do this (e.g., forcing IM to treat the input as 11 bits or use level to scale directly to 8 bits and then change output file bit depth without scaling)? I'm new to IM, so my apologies if this is something simple that I've just managed to miss.
This is on OS X 10.8.4 with IM:
Code: Select all
$convert -version
Version: ImageMagick 6.8.6-3 2013-09-11 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg png tiff xml zlib
convert test1.tif -auto-level -depth 8 -shave 0x36 -crop 5x3+10+0@ +repage +adjoin -rotate 90 out_imgs/test_5x3_ad_1_%02d.jpg
(To maximize # of component images that are exactly 696x520, since there doesn't appear to be a way to automatically tile like this.)
Any other random performance tips would be greatly appreciated as well. I've already switched to using jpeg-turbo.
Thanks!