- My test image is here: http://swharden.com/tmp/im/test.tif
- The image looks great when opened in ImageJ: http://swharden.com/tmp/im/test.png
- convert test.tif out.jpg produces a flat white image
- convert test.tif -evaluate divide 16 -depth 8 out.jpg produces a flat gray image
- convert test.tif -contrast-stretch 0.15x0.05% out.jpg produces a flat white image
[SOLVED] 32-bit TIF conversion problems
[SOLVED] 32-bit TIF conversion problems
I have a TIF containing data produced from a 12-bit camera, but it is saved as a 32-bit TIF. I am trying to convert it to JPG using the "convert" command line tool.
Last edited by swharden on 2018-08-01T14:00:50-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: 32-bit TIF conversion problems
First, we find what is in the image:
We get:
Pixels are stored as floating-point data, grayscale. On a scale of 0.0 to 1.0, the minimum (smallest) value is 9. So processing this in the normal way will show all white.
The easiest way to get a visible image is "-auto-level" which reduces the range to 0.0 to 1.0, but with a low mean so also use "-auto-gamma" to raise the mean:
This is IM v7. If using v6, use "convert" instead of "magick".
The output can be .jpg if you prefer.
Code: Select all
magick identify -verbose test12.tiff
Code: Select all
Geometry: 1392x1040+0+0
Units: PixelsPerInch
Colorspace: Gray
Type: Grayscale
Endianess: MSB
Depth: 32/16-bit
Channel depth:
Gray: 16-bit
Channel statistics:
Pixels: 1447680
Gray:
min: 589815 (9)
max: 5.09207e+007 (777)
mean: 5.52102e+006 (84.2454)
standard deviation: 773234 (11.7988)
kurtosis: 32.3131
skewness: -2.93325
entropy: 0
Colors: 127
The easiest way to get a visible image is "-auto-level" which reduces the range to 0.0 to 1.0, but with a low mean so also use "-auto-gamma" to raise the mean:
Code: Select all
magick test12.tiff -auto-level -auto-gamma out.png
The output can be .jpg if you prefer.
snibgo's IM pages: im.snibgo.com
Re: 32-bit TIF conversion problems
Thank you for your input! Unfortunately my problem still is not solved.
This is the output of magick identify -verbose test.tif
I am surprised to see:
magick test.tif -auto-level -auto-gamma out.png produces a solid black image.
My test image is here: http://swharden.com/tmp/im/test.tif
I still cannot figure out how to convert it to JPG with ImageMagick...
The image looks great when opened in ImageJ: http://swharden.com/tmp/im/test.png
Thank you in advance for your suggestions!
This is the output of magick identify -verbose test.tif
Code: Select all
Image: test.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 1392x1040+0+0
Units: PixelsPerInch
Type: Bilevel
Base type: Grayscale
Endianess: MSB
Colorspace: Gray
Depth: 32/1-bit
Channel depth:
Gray: 1-bit
Channel statistics:
Pixels: 1447680
Gray:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -1.#IND
Colors: 1
Histogram:
1447680: (4294967295,4294967295,4294967295) #FFFFFFFFFFFFFFFFFFFFFFFF gray(255)
Rendering intent: Undefined
Gamma: 0.454545
Alpha color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1392x1040+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Properties:
comment: ImageJ=1.48v
min=9.0
max=105.0
date:create: 2018-08-01T10:03:32-04:00
date:modify: 2018-07-30T15:40:17-04:00
quantum:format: floating-point
signature: d2d2c6e2965e3feb9390a5ea254753a088989feb8daa664b8834a9217e13c9c0
tiff:alpha: unspecified
tiff:endian: msb
tiff:photometric: min-is-black
tiff:rows-per-strip: 1040
Artifacts:
verbose: true
Tainted: False
Filesize: 5.791MB
Number pixels: 1.448M
Pixels per second: 45.24MB
User time: 0.063u
Elapsed time: 0:01.031
Version: ImageMagick 7.0.2-0 Q16 x64 2016-06-12 http://www.imagemagick.org
Code: Select all
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
My test image is here: http://swharden.com/tmp/im/test.tif
I still cannot figure out how to convert it to JPG with ImageMagick...
The image looks great when opened in ImageJ: http://swharden.com/tmp/im/test.png
Thank you in advance for your suggestions!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: 32-bit TIF conversion problems
But you are using non-HDRI IM, which clamps values that are out of range, so the maximum value you can see is 1.0. To use IM on this file, you need an HDRI version.swharden wrote:quantum:format: floating-point
snibgo's IM pages: im.snibgo.com
Re: 32-bit TIF conversion problems
Thanks for your reply! I now understand.
My problem was: The ImageMagick I had on my system did not support 32-bit images. I required a HDRI (high dynamic range imaging) build of ImageMagick. This is described on https://www.imagemagick.org/script/high ... -range.php
The fix was: Download a HDRI build of ImageMagick from https://www.imagemagick.org/script/download.php
magick identify -verbose test.tif now outputs:
Now this command works for me:
magick test.tif -auto-level -auto-gamma out.png
Personally I enjoy:
convert test.tif -auto-level -contrast-stretch 0.15x0.05% out.png
Thanks!
My problem was: The ImageMagick I had on my system did not support 32-bit images. I required a HDRI (high dynamic range imaging) build of ImageMagick. This is described on https://www.imagemagick.org/script/high ... -range.php
The fix was: Download a HDRI build of ImageMagick from https://www.imagemagick.org/script/download.php
magick identify -verbose test.tif now outputs:
Code: Select all
Image: test.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 1392x1040+0+0
Units: PixelsPerInch
Colorspace: Gray
Type: Grayscale
Endianess: MSB
Depth: 32/16-bit
Channel depth:
Gray: 16-bit
Channel statistics:
Pixels: 1447680
Gray:
min: 589815 (9)
max: 5.09207e+007 (777)
mean: 5.52102e+006 (84.2454)
standard deviation: 773234 (11.7988)
kurtosis: 32.3131
skewness: -2.93325
entropy: 0
Colors: 127
Histogram: [omitted for simplicity]
Rendering intent: Undefined
Gamma: 0.454545
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1392x1040+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Properties:
comment: ImageJ=1.48v
min=9.0
max=105.0
date:create: 2018-08-01T16:42:49-04:00
date:modify: 2018-08-01T16:42:46-04:00
quantum:format: floating-point
signature: 9ad4d28f2dd7badefc9ddd20436c9f00429b55124b343204028f3fb889b768e9
tiff:alpha: unspecified
tiff:endian: msb
tiff:photometric: min-is-black
tiff:rows-per-strip: 1040
Artifacts:
verbose: true
Tainted: False
Filesize: 5.52263MiB
Number pixels: 1447680
Pixels per second: 51.7031MB
User time: 0.031u
Elapsed time: 0:01.027
Version: ImageMagick 7.0.8-8 Q16 x64 2018-07-23 http://www.imagemagick.org
magick test.tif -auto-level -auto-gamma out.png
Personally I enjoy:
convert test.tif -auto-level -contrast-stretch 0.15x0.05% out.png
Thanks!