libvips / pyvips

python binding for libvips using cffi
MIT License
649 stars 50 forks source link

cannot load all slices #494

Closed nooneswarup closed 3 months ago

nooneswarup commented 3 months ago

tiffheader

test.tif: 6266x4271 uchar, 1 band, b-w, tiffload width: 6266 height: 4271 bands: 1 format: uchar coding: none interpretation: b-w xoffset: 0 yoffset: 0 xres: 1 yres: 1 filename: test.tif vips-loader: tiffload n-pages: 1 image-description: ImageJ=1.54f images=526 slices=526 loop=false bits-per-sample: 8 orientation: 1

test_image = pyvips.Image.tiffload(file) I tried test_image = pyvips.Image.tiffload(file, n = -1) and using page = 10 etc. but I can only read the slice 1. (Only works with n =0, page=0; im assuming since n-pages is 1)

How do I load all images?

jcupitt commented 3 months ago

Hello @nooneswarup,

Try tiffinfo on your file. It'll dump the complete structure and should show the issue. Alternatively, share your file somehow.

nooneswarup commented 3 months ago

Unfortunately I cannot share the file but, here is the tiffinfo -

TIFFReadDirectory: Warning, Unknown field with tag 50838 (0xc696) encountered. TIFFReadDirectory: Warning, Unknown field with tag 50839 (0xc697) encountered. === TIFF directory 0 === TIFF Directory at offset 0x8 (8) Subfile Type: (0 = 0x0) Image Width: 6266 Image Length: 4271 Bits/Sample: 8 Compression Scheme: None Photometric Interpretation: min-is-black Samples/Pixel: 1 Rows/Strip: 4271 Planar Configuration: single image plane ImageDescription: ImageJ=1.54f images=526 slices=526 loop=false

jcupitt commented 3 months ago

As you can see from tiffinfo, your file only contains one large monochrome image.

Perhaps the frames are laid out in a grid? What does it look like if you view it?

nooneswarup commented 3 months ago

If I open it in FIJI I can see the multiple z slices, and same on napari. Is there a way I can load all the slices? Tifffile also loads all of the image as a series.

jcupitt commented 3 months ago

I mean view it in a regular TIFF viewer, not one that might slice it up for you.

For example, vipsdisp will show the exact pixels in the file:

https://github.com/jcupitt/vipsdisp

It's on flathub for linux, or there are win binaries on the releases page.

jcupitt commented 3 months ago

Or irfanview / eog / loupe / mspaint etc etc.

jcupitt commented 3 months ago

Ah 4271 is prime, so they are probably not in a grid.

Is it really 526 slices, with each slice 4271 x 6266 pixels? That's a 14gb file. Maybe it hasn't been saved correctly? Or it has been saved as regular tiff, not bigtiff?

nooneswarup commented 3 months ago

If I open it with preview on mac, I can only see the first slice. Yes, that's a 14gb file. It's saved as a regular tiff and not bigtiff. I can try converting it to bigtiff and then try to use it?

jcupitt commented 3 months ago

Yes, regular tiff will only work for 2gb or maybe 4gb files. Try bigtiff.

nooneswarup commented 3 months ago

I just tried with bigtiff it works now, Thanks!

jcupitt commented 3 months ago

Great!

Regular TIFF uses 32-bit ints as offsets to point from one image to the next, so you can't have more than 4gb of images on one file. Some TIFF implementations use a signed int, so you can't have more than 2gb.

bigtiff uses 64-bit offsets everywhere, so files can be (almost) any size.