Bits lost along the way with convert -combine

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Ocirne94
Posts: 9
Joined: 2016-06-29T15:12:30-07:00
Authentication code: 1151

Bits lost along the way with convert -combine

Post by Ocirne94 »

Hi all,
I'm trying to use convert to combine the three r, g and b bands of a landsat scene into an rgb image.
The bands are 16-bits grayscale, the command I use is

Code: Select all

convert -combine {4,3,2}.tif -depth 16 rgb.tif
The result is indeed 16-bits-per-channel, but apparently during the process there is some 8-bits bottleneck: what I get is the 16-bits representation of 8-bit data, the histogram shows only 256 equally-spaced values, and the file size corresponds to 8 bits per channel.
I'm using ImageMagick 6.9.2-10 Q16 x86_64 20151218 on ubuntu 16.04, and the problem images are here (200 Mb):
https://mega.nz/#!ChNCSBBb!hU1_Oen9l0gN ... auwyr-yC_M

What am I missing here?
Thank you very much,
Enrico
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bits lost along the way with convert -combine

Post by fmw42 »

Read your input images before combining them. That is proper IM 6 syntax.

OK, so you have 3 separate grayscale images. Have you tried

Code: Select all

convert -quiet 4.tif 3.tif 2.tif -set colorspace sRGB -combine -depth 16 result.tif
However, using identify -verbose 4.tif, I see that your input data is 16/8-bits. That means that you extracted the data as 8-bits, but are storing it as 16 bits. So there are really only 8bits worth of grayscale information, which should be scaled to span the 16-bit range. So the software that you used to extract the channels and store in tif format converted the data to 8bits.

So there is really no point in saving as 16 bits. You might as well just use

Code: Select all

convert -quiet 4.tif 3.tif 2.tif -set colorspace sRGB -combine -depth 8 result.tif
This works for me, but your 4,3,2 channels are practically identical and so the result looks grayscale.
Ocirne94
Posts: 9
Joined: 2016-06-29T15:12:30-07:00
Authentication code: 1151

Re: Bits lost along the way with convert -combine

Post by Ocirne94 »

Now this is weird: opening the image (2.tif) with gimp I get the full 16-bits (there are more than 256 values and the histogram has a beautifully continuous and solid shape). So it really looks like IM is missing something... :(
P.S.: the channels are not identical, landsat images need a strong contrast curve if you want them to look natural. That's why they use 16-bits :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Bits lost along the way with convert -combine

Post by snibgo »

Ocirne94 wrote:... opening the image (2.tif) with gimp I get the full 16-bits (there are more than 256 values and the histogram has a beautifully continuous and solid shape).
What version of Gimp is that? I thought Gimp only had 8 bits per channel?
snibgo's IM pages: im.snibgo.com
Ocirne94
Posts: 9
Joined: 2016-06-29T15:12:30-07:00
Authentication code: 1151

Re: Bits lost along the way with convert -combine

Post by Ocirne94 »

Gimp 2.9.3, which supports up to 32-bits per channel and floating point.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bits lost along the way with convert -combine

Post by fmw42 »

To get 32-bit (floats) per channel for tiff, you will need at least Q16 HDRI compiled Imagemagick. Also see http://www.imagemagick.org/script/formats.php -defines for tiff.

"To specify a single-precision floating-point format, use -define quantum:format=floating-point"
Post Reply