Read with java: ome-tiff.companion.ome

Hello,

cc @dgault

Is there Java code to read the voxel size from such files: ome-tiff.companion.ome?

Thanks, Tischi

You should be able to read it as before with https://github.com/ome/bio-formats-examples/blob/bcd0fdd42a9788f733c5157bfcda53234ce87a3a/src/main/java/ReadPhysicalSize.java

The ImageReader should recognise the companion.ome extension.

1 Like

Thanks! That works. For future reference I put the Java code:

public class BioFormatsCalibrationReader
{
	private final File file;
	private String unit;
	private double[] voxelSize;

	public BioFormatsCalibrationReader( File file )
	{
		this.file = file;
		readCalibration( file );
	}

	private  void readCalibration( File file )
	{
		try
		{
			ServiceFactory factory = new ServiceFactory();
			OMEXMLService service = factory.getInstance( OMEXMLService.class );
			IMetadata meta = service.createOMEXMLMetadata();

			// create format reader
			IFormatReader reader = new ImageReader();
			reader.setMetadataStore( meta );

			// initialize file
			reader.setId( file.getAbsolutePath() );
			reader.setSeries( 0 );

			// read calibration
			unit = meta.getPixelsPhysicalSizeX( 0 ).unit().getSymbol();
			voxelSize = new double[ 3 ];
			voxelSize[ 0 ] = meta.getPixelsPhysicalSizeX( 0 ).value().doubleValue();
			voxelSize[ 1 ] = meta.getPixelsPhysicalSizeY( 0 ).value().doubleValue();
			voxelSize[ 2 ] = meta.getPixelsPhysicalSizeZ( 0 ).value().doubleValue();

		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}

	public String getUnit()
	{
		return unit;
	}

	public double[] getVoxelSize()
	{
		return voxelSize;
	}
}
2 Likes