Wondering if there's a speedy way to return specific pixel ranges of a given channel of an ome-tiff file using pyvips / libvips. The crop doesn't allow for channel specfics.
My OME-Tiff is large (10 GB+) so I don't want to load the entire image into memory.
Open to any suggestions and/or other workflows.
pyvips supports multipage documents as "toilet-roll" images (sorry). You set
n=-1to load all the pages, and they appear as a very tall, thin image, with the pages stacked vertically. The metadata itempage-heightgives the height in pixels of each sheet.Docs here:
https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffload
For example:
You can see this is a 15 page OME image. pyvips will load page 0 by default, and each page is 439 by 167 pixels. You can fetch the XML in
image-descriptionto see the full OME channel metadata.In Python you can do:
So you can use
cropto fetch a rect from a channel in the obvious way.Are you planning to generate patches for ML training? If you are,
fetchcan be much faster thancropfor small patches. This issue has sample code and some benchmarks --- in that example,croptakes 41s to make 12,000 32x32 patches, butfetchtakes just 0.5s.