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=-1
to load all the pages, and they appear as a very tall, thin image, with the pages stacked vertically. The metadata itempage-height
gives 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-description
to see the full OME channel metadata.In Python you can do:
So you can use
crop
to fetch a rect from a channel in the obvious way.Are you planning to generate patches for ML training? If you are,
fetch
can be much faster thancrop
for small patches. This issue has sample code and some benchmarks --- in that example,crop
takes 41s to make 12,000 32x32 patches, butfetch
takes just 0.5s.