2

I have an 8bit tiff file, that I open using tifffile like this

import tifffile as tiff
a=tiff.imread(path_to_file)

However, a.dtype then returns dtype('uint16'), i.e. it seems to have converted it into a 16bit file. I couldn't find an options that one could pass to imread that would prevent this. Is it possible to read the file into a numpy array without having the type changed?

ali_m
  • 71,714
  • 23
  • 223
  • 298
jacob
  • 869
  • 2
  • 10
  • 23
  • `tifffile` attempts to read the bit depth from the TIFF headers, so it's possible that this information is either missing or incorrect. Could you post a link to the image? – ali_m Jan 08 '16 at 20:19
  • https://www.dropbox.com/s/wguesn8x2hvrkep/control-0012_p000008t00000001z003c01.tif?dl=0 It is in the metadata, and other programs like ImageJ and Photoshop read it as 8bit. – jacob Jan 08 '16 at 20:39
  • Maybe try `TIFFfile` (see example in `help(tiff.TIFFfile)` about how to read the file into numpy array)? Also, see [this thread](https://stackoverflow.com/questions/7684695/numpy-array-of-an-i16-image-file) – vrs Jan 08 '16 at 20:45
  • 5
    The file has a color map, which is 16-bit. tifffile does not convert it to 8-bit, unlike other software. – cgohlke Jan 08 '16 at 21:43
  • @cgohlke how can I see that? ImageJ gives me "Bits per pixel: 8 (grayscale LUT)", but I can't see anything about a colormap. – jacob Jan 08 '16 at 23:08
  • 1
    You could use the tiffinfo tool from the libtiff library, which will show `Photometric Interpretation: palette color (RGB from colormap)` and `Color Map: (present)`. The values of the color map are always stored as 16-bit integers according to the Tiff specification. – cgohlke Jan 08 '16 at 23:44
  • thanks, good to know. I'm still a bit confused to what extent this is an intentional feature of tifffile, or just something that happens to be implemented this way, and which you might consider as an option in the future. Anyway, I can of course convert it back to 8-bit myself. – jacob Jan 09 '16 at 03:18
  • @cgohlke You should post your comments as an answer – ali_m Jan 10 '16 at 11:06

0 Answers0