These are chat archives for bigdataviewer/bigdataviewer-core

8th
Aug 2017
Jean-Yves Tinevez
@tinevez
Aug 08 2017 14:34
Hi all,
I have a piece of code that processes a small ROI in a large image, stored as a legit BDV, multi-res, HDF5 file. I load it from its SpimDataMinimal object.
The image is rather large (roughly 2000 x 2000 x 1000) but I only need a small ROI in the middle of it (typically 100 x 100 x 50).
Right now loading the full image from disk is what takes the most time.
Is there a way to prompt the loader to only load a designated portion of the image?
I browsed the API and could not found how to do that. I could however find how to load a sub-resolution image, but this is not what I am looking for.
Igor Pisarev
@igorpisarev
Aug 08 2017 22:20
Hi @tinevez,
Are you using bdv.img.hdf5.Hdf5ImageLoader class? If so, the following should work:
void process(File hdf5, SpimDataMinimal spimData, Interval roi) {
    AbstractSequenceDescription<?, ?, ?> sequenceDescription = spimData.getSequenceDescription();
    Hdf5ImageLoader hdf5Loader = new Hdf5ImageLoader(hdf5, /* hdf5 partitions */ null, sequenceDescription);
    for (TimePoint timepoint : sequenceDescription.getTimePoints().getTimePointsOrdered()) {
        for (BasicViewSetup setup : sequenceDescription.getViewSetupsOrdered()) {
            RandomAccessibleInterval<UnsignedShortType> img = hdf5Loader.getSetupImgLoader(setup.getId()).getImage(timepoint.getId(), 0); // full res
            RandomAccessibleInterval<UnsignedShortType> imgRoi = Views.interval(img, roi);
            // process imgRoi here, it will be lazily loaded when accessed
        }
    }
}