tiff image with 2 pages
I am new to pyvips, can someone give me a advice, how to use pyvips to load a tiff image which has two pages?
hers is my code:
img= pyvips.Image.new_from_file(path , access='sequential')
img.get("n-pages")
2
Hello @bageheyalu,
You can read a specific page by setting page, and read a set of consecutive pages with n. The tiffload docs have the details:
https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffload
Thank you very much, that helps a lot.
so this is great that you can read different pages of tiffs. the next question is how to manage tracking them as t.scale, t.xres, t.yres are the same as page 0.
I have also made a tiff file with 0-9 pages but when I read it in it only gives t.get("n-pages") == 7
The read-n-pages feature is really for volumetric images, like OME-TIFF. All the pages must have exactly the same size, same colour type, same format etc.
If you have an image where these vary, you'll need to process the pages one at a time.
Thank you @jcupitt Why would get("n-pages") return 7 when there are 10 pages in the image? ( this is after writing the image and then reading it back in)
e.g.
have an image that is 16384x16384 1 band
test.tiffsave("test2.tif", compression = "VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE",
properties=True, strip=False,
tile=True,
tile_width=32, # 16384 // 2**9
tile_height=32,
pyramid=True)
t = pyvips.Image.new_from_file("test2.tif")
print(t.get("n-pages") ) #gives 7
Sorry, I don't know. Perhaps your image has some sub-pages? libvips just counts pages in the top-level directory.
I will dig deeper to make sure it's not something I am doing.
Yep, definitely something I did wrong. its properly working. I must have mixed up some files. or not overwritten when I checked them.