Access pixel values in BigDataViewer h5 file



@bogovicj @tpietzsch

…I would like to access pixel values in an .h5/.xml file. I am trying below code, but when going through the resulting rai using Views.iterable( rai ).cursor() it only contains zeros (I checked the file and there are non-zero values). Could you let me know whether I am doing something conceptually wrong?

final ViewerImgLoader imgLoader = ( ViewerImgLoader ) source.spimData.getSequenceDescription().getImgLoader();
final ViewerSetupImgLoader< ?, ? > setupImgLoader = imgLoader.getSetupImgLoader( 0 );
RandomAccessibleInterval< T > rai =( RandomAccessibleInterval< T > ) setupImgLoader.getVolatileImage( 0, 2  )


Thanks to @StephanPreibisch I found a working solution:

final ViewerImgLoader imgLoader = ( ViewerImgLoader ) spimData.getSequenceDescription().getImgLoader();
final ViewerSetupImgLoader< ?, ? > setupImgLoader = imgLoader.getSetupImgLoader( 0 );
final RandomAccessibleInterval< T > image = ( RandomAccessibleInterval<T> ) setupImgLoader.getImage( 0, 2 );

Small but important difference is to use setupImgLoader.getImage rather than setupImgLoader.getVolatileImage.
I would be still curious to know though how one could get the volatile version to work (or what the point of it is)…


The point of volatile is for displaying it without blocking while waiting for data. Basically you could use the volatile version, then when you access a pixel, see whether it’s valid, if not retry until it is. But if you anyway want/need to wait until you have valid data, the setupImgLoader.getImage gives you that (and in a better way, because you do not need to actively poll until valid. It just blocks upon pixel access, until that pixel is available).