use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class Jpeg2000GrindTest method initializeWriter.
/**
* Initializes the writer.
* @param output The file where to write the compressed data.
* @param compression The compression to use.
* @param bigTiff Pass <code>true</code> to set the <code>bigTiff</code>
* flag, <code>false</code> otherwise.
* @throws Exception Thrown if an error occurred.
*/
private void initializeWriter(String output, String compression, boolean bigTiff) throws Exception {
ServiceFactory sf = new ServiceFactory();
OMEXMLService service = sf.getInstance(OMEXMLService.class);
IMetadata metadata = service.createOMEXMLMetadata();
metadata.setImageID("Image:0", 0);
metadata.setPixelsID("Pixels:0", 0);
metadata.setPixelsBinDataBigEndian(true, 0, 0);
metadata.setPixelsDimensionOrder(DimensionOrder.XYZCT, 0);
metadata.setPixelsType(ome.xml.model.enums.PixelType.fromString(PIXEL_TYPE), 0);
metadata.setPixelsSizeX(new PositiveInteger(SIZE_X), 0);
metadata.setPixelsSizeY(new PositiveInteger(SIZE_Y), 0);
metadata.setPixelsSizeZ(new PositiveInteger(1), 0);
metadata.setPixelsSizeC(new PositiveInteger(1), 0);
metadata.setPixelsSizeT(new PositiveInteger(SIZE_Z * SIZE_C * SIZE_T), 0);
metadata.setChannelID("Channel:0", 0, 0);
metadata.setChannelSamplesPerPixel(new PositiveInteger(1), 0, 0);
writer = new TiffWriter();
writer.setMetadataRetrieve(metadata);
writer.setCompression(compression);
writer.setWriteSequentially(false);
writer.setInterleaved(true);
writer.setBigTiff(bigTiff);
writer.setId(output);
bytesPerPixel = FormatTools.getBytesPerPixel(PIXEL_TYPE);
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class FileExportSPW method initializeMetadata.
/**
* Populate the minimum amount of metadata required to export a Plate.
*
* @param width
* the width (in pixels) of the image
* @param height
* the height (in pixels) of the image
* @param pixelType
* the pixel type of the image; @see loci.formats.FormatTools
*/
private IMetadata initializeMetadata(int width, int height, int pixelType) {
Exception exception = null;
try {
// create the OME-XML metadata storage object
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
OMEXMLMetadata meta = service.createOMEXMLMetadata();
meta.createRoot();
int plateIndex = 0;
// count of images
int series = 0;
int well = 0;
// Create Minimal 2x2 Plate
meta.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
meta.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
meta.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);
meta.setPlateRows(new PositiveInteger(rows), 0);
meta.setPlateColumns(new PositiveInteger(cols), 0);
meta.setPlateName("First test Plate", 0);
PositiveInteger pwidth = new PositiveInteger(width);
PositiveInteger pheight = new PositiveInteger(height);
char rowChar = 'A';
for (int row = 0; row < rows; row++) {
for (int column = 0; column < cols; column++) {
// set up well
String wellID = MetadataTools.createLSID("Well:", well);
meta.setWellID(wellID, plateIndex, well);
meta.setWellRow(new NonNegativeInteger(row), plateIndex, well);
meta.setWellColumn(new NonNegativeInteger(column), plateIndex, well);
for (int fov = 0; fov < fovPerWell; fov++) {
// Create Image
String imageName = rowChar + ":" + Integer.toString(column + 1) + ":FOV:" + Integer.toString(fov + 1);
String imageID = MetadataTools.createLSID("Image", well, fov);
meta.setImageID(imageID, series);
meta.setImageName(imageName, series);
String pixelsID = MetadataTools.createLSID("Pixels", row, well, fov);
meta.setPixelsID(pixelsID, series);
// specify that the pixel data is stored in big-endian format
// change 'TRUE' to 'FALSE' to specify little-endian format
meta.setPixelsBinDataBigEndian(Boolean.TRUE, series, 0);
// specify that the image is stored in ZCT order
meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, series);
// specify the pixel type of the image
meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), series);
// specify the dimensions of the image
meta.setPixelsSizeX(pwidth, series);
meta.setPixelsSizeY(pheight, series);
meta.setPixelsSizeZ(new PositiveInteger(1), series);
meta.setPixelsSizeC(new PositiveInteger(1), series);
meta.setPixelsSizeT(new PositiveInteger(sizeT), series);
// define each channel and specify the number of samples in the
// channel the number of samples is 3 for RGB images and 1 otherwise
String channelID = MetadataTools.createLSID("Channel", well, fov);
meta.setChannelID(channelID, series, 0);
meta.setChannelSamplesPerPixel(new PositiveInteger(1), series, 0);
// set sample
String wellSampleID = MetadataTools.createLSID("WellSample", well, fov);
meta.setWellSampleID(wellSampleID, 0, well, fov);
// NB sampleIndex here == series ie the image No
meta.setWellSampleIndex(new NonNegativeInteger(series), 0, well, fov);
meta.setWellSampleImageRef(imageID, 0, well, fov);
// add FLIM ModuloAlongT annotation if required
// CoreMetadata modlo = createModuloAnn();
// meta.addModuloAlong(meta, modlo, series);
series++;
}
// end of samples
well++;
}
rowChar++;
}
return meta;
} catch (DependencyException e) {
exception = e;
} catch (ServiceException e) {
exception = e;
} catch (EnumerationException e) {
exception = e;
}
System.err.println("Failed to populate OME-XML metadata object.");
exception.printStackTrace();
return null;
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class FileExport method initializeMetadata.
/**
* Populate the minimum amount of metadata required to export an image.
*
* @param width the width (in pixels) of the image
* @param height the height (in pixels) of the image
* @param pixelType the pixel type of the image; @see loci.formats.FormatTools
*/
private IMetadata initializeMetadata(int width, int height, int pixelType) {
Exception exception = null;
try {
// create the OME-XML metadata storage object
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
meta.createRoot();
// define each stack of images - this defines a single stack of images
meta.setImageID("Image:0", 0);
meta.setPixelsID("Pixels:0", 0);
// specify that the pixel data is stored in big-endian format
// change 'TRUE' to 'FALSE' to specify little-endian format
meta.setPixelsBinDataBigEndian(Boolean.TRUE, 0, 0);
// specify that the images are stored in ZCT order
meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, 0);
// specify that the pixel type of the images
meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), 0);
// specify the dimensions of the images
meta.setPixelsSizeX(new PositiveInteger(width), 0);
meta.setPixelsSizeY(new PositiveInteger(height), 0);
meta.setPixelsSizeZ(new PositiveInteger(1), 0);
meta.setPixelsSizeC(new PositiveInteger(1), 0);
meta.setPixelsSizeT(new PositiveInteger(1), 0);
// define each channel and specify the number of samples in the channel
// the number of samples is 3 for RGB images and 1 otherwise
meta.setChannelID("Channel:0:0", 0, 0);
meta.setChannelSamplesPerPixel(new PositiveInteger(1), 0, 0);
return meta;
} catch (DependencyException e) {
exception = e;
} catch (ServiceException e) {
exception = e;
} catch (EnumerationException e) {
exception = e;
}
System.err.println("Failed to populate OME-XML metadata object.");
exception.printStackTrace();
return null;
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class OBFReader method initFile.
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
currentInflatedFrame.series = -1;
currentInflatedFrame.number = -1;
in = new RandomAccessInputStream(id);
file_version = getFileVersion(in);
long stackPosition = in.readLong();
final int lengthOfDescription = in.readInt();
final String description = in.readString(lengthOfDescription);
metadata.put("Description", description);
if (file_version >= 2) {
final long meta_data_position = in.readLong();
final long current_position = in.getFilePointer();
in.seek(meta_data_position);
for (String key = readString(); key.length() > 0; key = readString()) {
if (key.equals("ome_xml")) {
final String ome_xml = readString();
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
if (service.validateOMEXML(ome_xml)) {
ome_meta_data = service.createOMEXMLMetadata(ome_xml);
for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
if (ome_meta_data.getPixelsBigEndian(image) == null) {
ome_meta_data.setPixelsBigEndian(Boolean.FALSE, image);
}
int channels = ome_meta_data.getChannelCount(image);
for (int channel = 0; channel != channels; ++channel) {
if (ome_meta_data.getChannelSamplesPerPixel(image, channel) == null) {
ome_meta_data.setChannelSamplesPerPixel(new PositiveInteger(1), image, channel);
}
}
}
service.convertMetadata(ome_meta_data, metadataStore);
OMEXMLMetadata reference = service.getOMEMetadata(service.asRetrieve(metadataStore));
for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
service.addMetadataOnly(reference, image);
}
}
} catch (DependencyException exception) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, exception);
} catch (ServiceException exception) {
throw new FormatException(exception);
} catch (Exception e) {
LOGGER.warn("Could not parse OME-XML metadata", e);
}
break;
} else {
addGlobalMeta(key, readString());
}
}
in.seek(current_position);
}
if (stackPosition != 0) {
core.clear();
do {
stackPosition = initStack(stackPosition);
} while (stackPosition != 0);
}
if (ome_meta_data == null) {
MetadataTools.populatePixels(metadataStore, this);
for (int image = 0; image != core.size(); ++image) {
CoreMetadata meta_data = core.get(image);
final String name = meta_data.seriesMetadata.get("Name").toString();
metadataStore.setImageName(name, image);
@SuppressWarnings("unchecked") final List<Double> lengths = (List<Double>) meta_data.seriesMetadata.get("Lengths");
if (lengths.size() > 0) {
double lengthX = Math.abs(lengths.get(0));
if (lengthX < 0.01) {
lengthX *= 1000000;
}
if (lengthX > 0) {
Length physicalSizeX = FormatTools.getPhysicalSizeX(lengthX / meta_data.sizeX, UNITS.MICROMETER);
if (physicalSizeX != null) {
metadataStore.setPixelsPhysicalSizeX(physicalSizeX, image);
}
}
}
if (lengths.size() > 1) {
double lengthY = Math.abs(lengths.get(1));
if (lengthY < 0.01) {
lengthY *= 1000000;
}
if (lengthY > 0) {
Length physicalSizeY = FormatTools.getPhysicalSizeY(lengthY / meta_data.sizeY, UNITS.MICROMETER);
if (physicalSizeY != null) {
metadataStore.setPixelsPhysicalSizeY(physicalSizeY, image);
}
}
}
if (lengths.size() > 2) {
double lengthZ = Math.abs(lengths.get(2));
if (lengthZ < 0.01) {
lengthZ *= 1000000;
}
if (lengthZ > 0) {
Length physicalSizeZ = FormatTools.getPhysicalSizeZ(lengthZ / meta_data.sizeZ, UNITS.MICROMETER);
if (physicalSizeZ != null) {
metadataStore.setPixelsPhysicalSizeZ(physicalSizeZ, image);
}
}
}
}
}
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class OMETiffWriter method populateImage.
private void populateImage(OMEXMLMetadata omeMeta, int series) {
String dimensionOrder = omeMeta.getPixelsDimensionOrder(series).toString();
int sizeZ = omeMeta.getPixelsSizeZ(series).getValue().intValue();
int sizeC = omeMeta.getPixelsSizeC(series).getValue().intValue();
int sizeT = omeMeta.getPixelsSizeT(series).getValue().intValue();
int imageCount = getPlaneCount();
if (imageCount == 0) {
omeMeta.setTiffDataPlaneCount(new NonNegativeInteger(0), series, 0);
return;
}
PositiveInteger samplesPerPixel = new PositiveInteger((sizeZ * sizeC * sizeT) / imageCount);
for (int c = 0; c < omeMeta.getChannelCount(series); c++) {
omeMeta.setChannelSamplesPerPixel(samplesPerPixel, series, c);
}
sizeC /= samplesPerPixel.getValue();
int nextPlane = 0;
for (int plane = 0; plane < imageCount; plane++) {
int[] zct = FormatTools.getZCTCoords(dimensionOrder, sizeZ, sizeC, sizeT, imageCount, plane);
int planeIndex = plane;
if (imageLocations[series].length < imageCount) {
planeIndex /= (imageCount / imageLocations[series].length);
}
String filename = imageLocations[series][planeIndex];
if (filename != null) {
filename = new Location(filename).getName();
Integer ifdIndex = ifdCounts.get(filename);
int ifd = ifdIndex == null ? 0 : ifdIndex.intValue();
omeMeta.setUUIDFileName(filename, series, nextPlane);
String uuid = "urn:uuid:" + getUUID(filename);
omeMeta.setUUIDValue(uuid, series, nextPlane);
// fill in any non-default TiffData attributes
populateTiffData(omeMeta, zct, ifd, series, nextPlane);
ifdCounts.put(filename, ifd + 1);
nextPlane++;
}
}
}
Aggregations