Open idc9 opened 9 months ago
Hi again @idc9,
You'll get that error if you make an out of order read from a sequential image. Perhaps you passed access="sequential"
by mistake?
It's usually best to post small, complete, runnable programs rather than code fragments, or I won't be able to test them unless I spend some time writing a code harness.
I tried:
#!/usr/bin/env python3
import sys
import pyvips
level = int(sys.argv[2])
image = pyvips.Image.new_from_file(sys.argv[1], page=level)
for _ in range(100):
patch = image.crop(0, 0, image.width, image.height).numpy()
Then ran it with:
$ vips copy ~/pics/nina.jpg x.tif[pyramid,compression=jpeg,tile]
$ ./crop2.py x.tif 6
$
Add it seems to work.
I had a look at your test file, it's a Perkin-Elmer QPI, so it won't work with a standard TIFF loader. You'll need a specialized load library for this file format.
Perhaps you could save as OME-TIFF? That should load OK.
Thanks again for the very fast response!
It's usually best to post small, complete, runnable programs rather than code fragments
That is a complete runnable program (edited to add the imports!), not a part of a larger script. I had not previously called 'access=sequential'`.
In fact the exact same behavior occurs when I try any of the access options (None, sequential, random). Note I restart the notebook before calling the different options.
vips_image = pyvips.Image.new_from_file(vips_filename=fpath, page=page_idx)
vips_image = pyvips.Image.new_from_file(vips_filename=fpath, page=page_idx, access='random')
vips_image = pyvips.Image.new_from_file(vips_filename=fpath, page=page_idx, access='sequential')
pyvips seems to work otherwise with this image format. So far the only issue I've encoutnered is this double loading issue. This seems like a bug in pyvips to me since it works on the first load, but not the second load.
Perhaps you could save as OME-TIFF?
That would be a problem for our application; we would like to use pyvips on the original image.
pyvips seems to work otherwise with this image format
It's a plane-separated pyramid, unfortunately, so it won't work. It's to do with the way the reduced resolution levels are coded -- OME-TIFF (which libvips does support) puts the reduced res levels into subifds, but this QPI has them all one after the other, with the metadata about the file structure coded into the XML in the imagedescription.
Have a look at the tiffinfo
output (and get a large mug of tea ready first).
Does the fact that reading in the image twice throws an error not suggest there is an issue with pyvips?
That's just a minor symptom -- the cause is this TIFF file being way outside the supported range for any general purpose TIFF reader.
Options off the top of my head:
tifffile
, but getting a nice RGB image will take some work. Maybe a week's effort? It depends how much of the QPI format you want to support.
Reading in an image from a qptiff file breaks when I run the same code twice.
If I run the below once it works. If I run it again (I'm using a jupyter notebook) it throws an error. If I run it a third time it throws a different error.
I'm not able to post the image publicly but I've emailed it to @jcupitt.
Error message after second call
Error message after third call
System details
I installed pyvips using conda install.