Saving Tiff using BioFormats

Hi @joshmoore @dgault,

We did an experiment saving files as ome.tif and found a “strange” behaviour.

When we called the output file image.ome.tif the physicalPixelSizeZ was stored correctly.

When we however called the output file image.tif (that is without the ome) the physicalPixelSizeZ was not stored correctly.

physicalPixelSizeX and physicalPixelSizeY were however stored in both cases.

Is this a bug or a feature?

That would be as expected. For standard Tiff the physical sizes will be stored when possible in the baseline IFD tags . In this case for physical sizes it will be and along with There is however no equivalent tag for physical size Z.


Ok, makes some sense.

However, would it be possible to throw a warning during the writing?
Let’s say I use meta.setPixelsPhysicalSizeZ(...) in my code and then save with a filename ending on .tif: @RainerNano and I would find it helpful to have a warning:

[WARNING] PhysicalPixelSizeZ was set but cannot be represented by Tiff files. Consider saving as ome.tif instead.
1 Like

That seems like a good idea to at least have a warning. Ive opened an enhancement issue for this:

1 Like

A related question: given I have an ImagePlus, how do I create a Length object?

new Length( ?, ? ); 


Generally we use helper methods in the FormatTools class for creating the physical sizes:

Length getPhysicalSizeZ(Double value, Unit<Length> unit)

for example:
Length physicalSizeZ = FormatTools.getPhysicalSizeZ(value, UNITS.MICROMETER);

So the method takes a double for the value and a unit from ome.units.UNITS.

Thanks! Is there a convenience method to get the Unit from and ImagePlus?

This is a bit difficult because a Calibration you get from an ImagePlus can hold any string as a unit. It doesn’t have to be a valid unit string. Additionally, many images classically used in ImageJ store their unit as micron, which would require some special casing for conversion.

But if you assume your image is in SI units, you can get the Unit from the static method CreateBaseUnit (which I found in the javadoc):

#@ ImagePlus imp
import ome.units.unit.Unit
unit = Unit.CreateBaseUnit("SI.METRE", imp.getCalibration().getUnit())
println unit.getSymbol()

Maybe there is a better convenience method that I’m not aware of??


As a very late follow up, the above method should work fine. The Bio-Formats exporter uses similar for setting physical sizes:

FormatTools.getPhysicalSizeX(imp.getCalibration().pixelWidth, imp.getCalibration().getXUnit())
FormatTools.getPhysicalSizeY(imp.getCalibration().pixelHeight, imp.getCalibration().getYUnit())
FormatTools.getPhysicalSizeZ(imp.getCalibration().pixelDepth, imp.getCalibration().getZUnit())
1 Like