Reading the Calibration field of an ImagePlus WITHOUT opening it

Is it possible to access the fields of the Calibration or OriginalFileInfo that can be found in an ImagePlus, without actually opening it?

For instance I would just like to know what is the pixel sizes, spatial units and image sizes, but without opening the image in ImageJ. Just from the file name, knowing that it is an image.

Hi @tinevez,

This blurb checks for size (not Calibration) and has seemed to work for me in the past -
in the sense that it’s fast enough that I know it isn’t reading the entire image.
It looks like the ImageReader class can get other metadata too.

I can’t confidently say much though, about what it will read for a function call like this one.

2 Likes

Here is what I did, based on bio-formats as well.
I just create an import process, trigger the import preparation, but do not read the pixels themselves.

			DebugTools.setRootLevel( "ERROR" );
			final ImporterOptions options = new ImporterOptions();
			options.setId( imageFile );
			options.setQuiet( true );
			options.setWindowless( true );
			final ImportProcess process = new ImportProcess( options );
			if ( !process.execute() )
			{
				errorMessage = "Error while preparing the import of metadata.";
				return null;
			}

			final IMetadata metadata = process.getOMEMetadata();
			final Length pixelsPhysicalSizeX = metadata.getPixelsPhysicalSizeX( series );
			final Length pixelsPhysicalSizeY = metadata.getPixelsPhysicalSizeY( series );
			final Length pixelsPhysicalSizeZ = metadata.getPixelsPhysicalSizeZ( series );
			final Time timeIncrement = metadata.getPixelsTimeIncrement( series );
			final PositiveInteger sizeX = metadata.getPixelsSizeX( series );
			final PositiveInteger sizeY = metadata.getPixelsSizeY( series );
			final PositiveInteger sizeZ = metadata.getPixelsSizeZ( series );
			final PositiveInteger sizeT = metadata.getPixelsSizeT( series );
2 Likes

Just to add yet another possibility, here’s what I did using ImageJ2 functionality, i.e. SCIFIO’s FormatService:

I don’t remember the performance implications in detail, though…

3 Likes