Hi Roger,
we are trying to create and save images from scratch. We already used an OMEXMLMetadataStore object and the MetadataTools.populateMetadata() method. Here is how we tried to save the image data:
- Code: Select all
public static void main(String[] args) throws Exception {
// dimensions of desired demo image
int x = 30, y = 20, c = 6, z = 10, t = 5;
int pixelType = FormatTools.UINT8;
// maybe this is the problem: how to organize the image data?
byte[] img =
new byte[x * y * FormatTools.getBytesPerPixel(pixelType)];
for (int i=0; i<img.length; i++)
img[i] = (byte) (256 * Math.random());
// create metadata object with minimum required metadata fields
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
MetadataTools.populateMetadata(meta, 0, null, false, "XYZCT",
FormatTools.getPixelTypeString(pixelType), x, y, z, c, t, 1);
// write tif image
IFormatWriter writer =
new ImageWriter().getWriter("/tmp/imageDemo.tif");
writer.setMetadataRetrieve(meta);
writer.setId("/tmp/imageDemo.tif");
writer.setWriteSequentially(true);
// We are not sure over which dimensions we have to loop...
for (int j=0;j<t*c*z;++j) {
writer.saveBytes(j, img);
}
writer.close();
}
Note that we just use random data here and have all image planes contain the same contents. When we open the image in ImageJ (without Bioformats) ImageJ reads it as a stack with t=1, c=1 and 300 z-slices (the units can be ignored for the moment):
Width: 30.00 cm (30)
Height: 20.00 cm (20)
Depth: 300.00 cm (300)
Resolution: 1 pixels per cm
Voxel size: 1x1x1 cm
ID: -2
Coordinate origin: 0,0,0
Bits per pixel: 8 (grayscale LUT)
Display range: 0-255
Opening it with the Bioformats Importer yields the following meta data:
<Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="1" SizeT="300" SizeX="30" SizeY="20" SizeZ="1" Type="uint8">
So, obviously the Tif file contains either wrong meta data, or ImageJ and Bioformats cannot match the meta data in the file to the data actually available. In addition, interpreting the metadata seems to be done different by ImageJ and Bioformats, however, we would expect this to be unified.
Thanks for your help and best regards,
Birgit