xulman / ome-zarr-fiji-ui

GUI Dialog to show structure of an ome.zarr dataset and to allow the user to cherry-pick image of interest, in Fiji.
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Show resolution layers as ImagePlus #3

Open tischi opened 2 years ago

tischi commented 2 years ago

@bogovicj

In order to determine the size in MB of a source at some level I guess we would need some way to determine the number of bits for all the imglib2 Types, do we have something for that?

If we want to show the images as an ImagePlus I guess it could be also interesting to know how large the image would be, because there are less types (8-bit, 16-bit and 32-bit float).

I am currently using below code for the translation, does that make sense to you?

private ImagePlus getImagePlus( Source< T > source, int level )
    {
        final RandomAccessibleInterval< T > raiXYZT = getRAIXYZT( source, level );
        final IntervalView< T > raiXYZTC = Views.addDimension( raiXYZT, 0, 0 );
        final IntervalView< T > raiXYCZT = Views.permute( Views.permute( raiXYZTC, 4, 3 ), 3, 2);
        final ImagePlus imagePlus = ImageJFunctions.wrap( raiXYCZT, source.getName() );
        return imagePlus;
    }

private RandomAccessibleInterval< T > getRAIXYZT( Source< T > source, int level )
    {
        int numTimepoints = 0;
        while ( source.isPresent( numTimepoints ) )
        {
            numTimepoints++;
            if ( numTimepoints >= Integer.MAX_VALUE )
            {
                throw new RuntimeException("The source " + source.getName() + " appears to contain more than " + Integer.MAX_VALUE + " time points; maybe something is wrong?");
            }
        }

        return getRAIXYZT( source, level, numTimepoints );
    }

    private RandomAccessibleInterval< T > getRAIXYZT( Source< T > source, int level, int numTimepoints )
    {
        final ArrayList< RandomAccessibleInterval< T > > rais = new ArrayList<>();
        for ( int t = 0; t < numTimepoints; t++ )
        {
            rais.add( source.getSource( t, level ) );
        }
        return Views.stack( rais );
    }
bogovicj commented 2 years ago

Your code makes sense except I'm not sure how it would handle types that ImageJ can't show...

Here's how we're doing conversion, which has worked okay so far. N5-centric, not as general as imglib2 though.

all the imglib2 Types, do we have something for that?

Not for all imglib2 types, but for many of them. every RealType can give you its getBitsPerPixel. That covers most interesting types except for RGBTypes. In any case, I'd lean toward only providing size estimates for NativeTypes anyway.

My use case is tied more closely with n5, so I can grab bit depth directly from the DataType. I think it would be straightforward to extend to imglib2 generally if we constrain to NativeTypes.

How does this sound to you?

tischi commented 2 years ago

Here's how we're doing conversion, which has worked okay so far. N5-centric, not as general as imglib2 though.

Maybe, if you can get hold of Stephan Preibisch, you could chat with him about this? I think he implemented the ImageJFunctions.wrap(...).

My use case is tied more closely with n5, so I can grab bit depth directly from the DataType. I think it would be straightforward to extend to imglib2 generally if we constrain to NativeTypes.

Sounds very good!