Page 1 of 1

32bit single channel tiffs?

Posted: 2008-04-04T08:29:33-07:00
by jpoczatek
I've been trying to use 'convert' to deal with some 32bit grayscale tiffs and the only thing I can get out is blank images (all 0 or 255 for example trying to convert to a .jpg for example).

I've tried more than a few variations, eg:

Code: Select all

convert -depth 32 -define quantum:format=floating-point image.tif -equalize -depth 8 8bit.tif
convert -depth 32 -define quantum:format=floating-point image.tif -equalize image.jpg
etc

Probably missing something simple, so maybe somebody can give me a hint.

Trying say "identify -depth 32 -define quantum:format=floating-point image.tif" on IM Q16 gives:

Code: Select all

Image: image.tif
  Format: TIFF (Tagged Image File Format)
  Class: DirectClass
  Geometry: 256x256+0+0
  Type: Bilevel
  Endianess: MSB
  Colorspace: Gray
  Depth: 1-bit
  Channel depth:
    Gray: 1-bit
  Channel statistics:
    Gray:
      Min: 1 (1)
      Max: 1 (1)
      Mean: 1 (1)
      Standard deviation: 0 (0)
  Histogram:
     65536: (4294967295,4294967295,4294967295) #FFFFFFFFFFFFFFFFFFFFFFFF white
  Rendering intent: Undefined
  Resolution: 72x72
  Units: PixelsPerInch
  Filesize: 256.176kb
  Interlace: None
  Background color: white
  Border color: rgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Page geometry: 256x256+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: TopLeft
  Comment: ImageJ=1.38x
min=21.0
max=6290.0

  Signature: 4927510809c83fb6af6d43e7a7d10e9c752e1c60febe566d490bdd72d9d37d36
  Tiff:rows-per-strip: 8
  Tainted: False
  Version: ImageMagick 6.3.5 09/25/07 Q16 http://www.imagemagick.org
Which doesn't make sense. Trying it on IM Q32 is a little better:

Code: Select all

Image: image.tif
 Format: TIFF (Tagged Image File Format)
 Class: DirectClass
 Geometry: 256x256+0+0
 Resolution: 72x72
 Print size: 3.55556x3.55556
 Units: PixelsPerInch
 Type: Bilevel
 Endianess: MSB
 Colorspace: Gray
 Depth: 32-bit
 Channel depth:
   gray: 32-bit
 Channel statistics:
   gray:
     min: 0 (0)
     max: 0 (0)
     mean: 0 (0)
     standard deviation: -0 (-0)
 Histogram:
    65536: (         0,         0,         0) #000000000000000000000000 black
 Rendering intent: Undefined
 Interlace: None
 Background color: rgb(255,255,255)
 Border color: rgb(223,223,223)
 Matte color: rgb(189,189,189)
 Transparent color: rgb(1.16415e-08%,1.16415e-08%,1.16415e-08%)
 Page geometry: 256x256+0+0
 Dispose: Undefined
 Iterations: 0
 Compression: None
 Orientation: TopLeft
 Properties:
   comment: ImageJ=1.38x
min=21.0
max=6290.0

   create-date: 2008-04-03T13:42:21-04:00
   modify-date: 2008-04-02T13:09:32-04:00
   signature: 599c1bb5ffd4b87229a81958f33f1060821cd01cd7aa7ccafa0d862f4522f3f6
   tiff:rows-per-strip: 8
 Artifacts:
   quantum:format: floating-point
   verbose: true
 Tainted: False
 Filesize: 256.176kb
 Number pixels: 64kb
 Version: ImageMagick 6.4.0 04/03/08 Q32 http://www.imagemagick.org
It get's the depth right, but the pixel values are all wrong. Some actual pixel statistics are in comment field in the header: min 21.0, max 6290.0 . Is this an endian-ness issue? Wrong rows/strip? Weird header? I'm a little out of my depth here...

Anyone have any ideas?

Is there anyway I can ignore the header? I looking at the raw binary data in Mathematica, and if you read in the last 256*256 32bit blocks I can plot those numbers (base 10) and reconstruct the image.

Re: 32bit single channel tiffs?

Posted: 2008-04-04T09:53:33-07:00
by fmw42
If image.tif is your input, then I think your -verbose info is saying that you have a binary image with a matte color of 74 and a border color of 233 and all the graylevels are black (from the min and max and mean and std). So even though it is 32-bit, it is basically a 32-bit binary image - with one color - black (apart from the bordercolor and matte). Thus equalize will do nothing for you. You have only one graylevel to equalize. If this is not your input image, then please post your verbose info on that and insert a link to your input image.

Re: 32bit single channel tiffs?

Posted: 2008-04-04T11:21:58-07:00
by jpoczatek
I was getting a little flag happy and pasted the wrong output. (This is the same file as image.tif)

Code: Select all

$ identify -verbose 080319_11-1-4x10_m25.91_sum.tif

080319_11-1-4x10_m25.91_sum.tif TIFF 256x256 256x256+0+0 DirectClass
32-bit 256.176kb
shiny:32bit_test collin$ identify -verbose 080319_11-1-4x10_m25.91_sum.tif
Image: 080319_11-1-4x10_m25.91_sum.tif
 Format: TIFF (Tagged Image File Format)
 Class: DirectClass
 Geometry: 256x256+0+0
 Resolution: 72x72
 Print size: 3.55556x3.55556
 Units: PixelsPerInch
 Type: Grayscale
 Endianess: MSB
 Colorspace: Gray
 Depth: 32-bit
 Channel depth:
   gray: 32-bit
 Channel statistics:
   gray:
     min: 3.97223e-34 (9.24857e-44)
     max: 9.80934e-29 (2.28392e-38)
     mean: 4.40187e-29 (1.02489e-38)
     standard deviation: 2.96906e-29 (6.91289e-39)
 Rendering intent: Undefined
 Interlace: None
 Background color: rgb(255,255,255)
 Border color: rgb(223,223,223)
 Matte color: rgb(189,189,189)
 Transparent color: rgb(1.16415e-08%,1.16415e-08%,1.16415e-08%)
 Page geometry: 256x256+0+0
 Dispose: Undefined
 Iterations: 0
 Compression: None
 Orientation: TopLeft
 Properties:
   comment: ImageJ=1.38x
min=21.0
max=6290.0
   create-date: 2008-04-03T13:42:21-04:00
   modify-date: 2008-04-02T13:09:32-04:00
   signature: 599c1bb5ffd4b87229a81958f33f1060821cd01cd7aa7ccafa0d862f4522f3f6
   tiff:rows-per-strip: 8
 Artifacts:
   verbose: true
 Tainted: False
 Filesize: 256.176kb
 Number pixels: 64kb
 Version: ImageMagick 6.4.0 04/03/08 Q32 http://www.imagemagick.org
Notice the min/max values aren't 0, but aren't the 21/6290 I'd expect. Endian difference? identify doesn't seem to recognize '-endian'. I tried both '-endian lsb' and '-endian msb' with convert and got nowhere...

Here's a link to the image.
http://www.borisepstein.info/temp/08031 ... 91_sum.tif

Thanks.

Re: 32bit single channel tiffs?

Posted: 2008-04-04T12:07:59-07:00
by fmw42
Please explain what you expect to see after your conversion.

Also I am not sure you uploaded the correct image. I downloaded it (and it was all white) and renamed it and did a verbose info and this is what I got (still 1-bit all black pixels).

convert test_white.tif -verbose info:
Image: test_white.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 256x256+0+0
Resolution: 72x72
Print size: 3.55556x3.55556
Units: PixelsPerInch
Type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 32/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: -0 (-0)
Histogram:
65536: ( 0, 0, 0) #000000000000000000000000 black
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 256x256+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Properties:
comment: ImageJ=1.38x
min=21.0
max=6290.0

create-date: 2008-04-04T12:03:34-07:00
modify-date: 2008-04-04T12:03:34-07:00
signature: 599c1bb5ffd4b87229a81958f33f1060821cd01cd7aa7ccafa0d862f4522f3f6
tiff:rows-per-strip: 8
Artifacts:
verbose: true
Tainted: False
Filesize: 0b
Number pixels: 64kb
Version: ImageMagick 6.4.0 04/04/08 Q16 http://www.imagemagick.org

Re: 32bit single channel tiffs?

Posted: 2008-04-04T13:35:07-07:00
by jpoczatek
Please explain what you expect to see after your conversion.
I'd just like to have simple 8 bit tifs/jpegs that have good contrast/range of grey values for automatic document creation.

I've been using IM to write some scripts to do automatic adjustments of images (16bit integer tifs) like equalize/normailze/threshold and every thing has been fine. Perhaps it's worth mentioning that these tifs are 'data', that is the pixel values represent some physical measurement. Most of the data fits well in a 16 bit integer (this is also kind of a legacy format), but some hits the ~65k limit (or aren't really integers) hence a 32 bit float for a pixel.

Since everything was working so smoothly for the 16 bit images, I was trying to get the same operations to work with the 32 bit images.

The image I uploaded is correct (I downloaded from the link I posted and compared), and has pixels that aren't 0/1. That is if you open it in the software that created it, http://rsb.info.nih.gov/ij/ , or look at the last 256x256 32bit blocks as floats. Then you have a nice distribution of values from 21.0-6290.0

I -do- get the same 'identify -verbose' output under IM compiled with quantum=16 but not with IM compiled with quantum=32, but neither give me the expected min/max values.

Maybe these files are just too strange and I'm going to have to deal with the actual array of values, I was just hoping IM could do it so I could just write a script.

Re: 32bit single channel tiffs?

Posted: 2008-04-04T15:25:30-07:00
by magick
The problem is that the image incorrectly reports the sample format as IEEE floating point when it is unsigned. When we force the unsigned format (with a quick debugging patch for GrayQuantum/32-bit in ExportQuantumPixels() of magick/quantum.c), the correct image values are returned (they match the output of the tifftopnm program).

Re: 32bit single channel tiffs?

Posted: 2008-04-07T09:50:10-07:00
by jpoczatek
magick,

Thanks for looking into that. That kinda makes sense. Though oddly if the tif has positive and negative values (according to ImageJ) and thus has to be "signed" in some way, 'identify' still gives odd values. However, and somewhat surprisingly, this works:

Code: Select all

[lyon@cpoczatek][32bit_test] tifftopnm 080319_11-1-4x10_m25.91_sum.tif >> foo.pnm
tifftopnm: writing PGM file
tifftopnm: Sorry, can not handle images with 32-bit samples
tifftopnm: In-memory conversion failed; using more primitive row-by-row conversion.
[lyon@cpoczatek][32bit_test] convert foo.pnm -equalize foo.jpg


in that it gives me a grayscale image that has a nice full range of values. I'm going to have to talk to the ImageJ list since this apparent ambiguity of the file format is a little troubling.

Thanks again,
Collin

Re: 32bit single channel tiffs?

Posted: 2008-04-07T10:27:17-07:00
by fmw42
I just tried to import an 8-bit grayscale png to ImageJ, convert it to 32-bits and then export it as a 32-bit grayscale tiff from ImageJ. I then tried to display it in several tools: Mac Preview, GraphicConverter, Debabelizer, Photoshop and IM. Debabelizer would not open it. Preview, GraphicConverter and Photoshop and even IM displayed it as all white or all black. I then tried

convert lena2g.tif -contrast-stretch 0% lena2g_cs0.tif
display lena2g_cs0.tif

but it was still all black.

This is in IM 6.4.0-4

But like you its verbose info showed the orginal converted tif as a 1-bit tif

convert lena2g.tif -verbose info:
Image: lena2g.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 128x128+0+0
Resolution: 72x72
Print size: 1.77778x1.77778
Units: PixelsPerInch
Type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 32/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: -0 (-0)
Histogram:
16384: ( 0, 0, 0) #000000000000000000000000 black
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 128x128+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: TopLeft
Properties:
comment: ImageJ=1.38x
min=28.0
max=233.0

create-date: 2008-04-07T10:15:36-07:00
modify-date: 2008-04-07T10:15:36-07:00
signature: 3381de4ca9f3a477f25989dfc8b744e7916046b7aa369f61a9a2f7dc0963ec9e
tiff:rows-per-strip: 16
Artifacts:
verbose: true
Tainted: False
Filesize: 0b
Number pixels: 16kb
Version: ImageMagick 6.4.0 04/04/08 Q16 http://www.imagemagick.org
freds-mac-mini:~ fred$