use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class TiffWriterTest 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.
* @return See above.
* @throws Exception Thrown if an error occurred.
*/
private TiffWriter initializeWriter(String output, String compression, boolean bigTiff) throws Exception {
IMetadata newMetadata = service.createOMEXMLMetadata();
MetadataConverter.convertMetadata(metadata, newMetadata);
TiffWriter writer = new TiffWriter();
writer.setMetadataRetrieve(newMetadata);
writer.setCompression(compression);
writer.setWriteSequentially(true);
writer.setInterleaved(false);
writer.setBigTiff(bigTiff);
writer.setId(output);
return writer;
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FileConvert method initialize.
/**
* Set up the file reader and writer, ensuring that the input file is
* associated with the reader and the output file is associated with the
* writer.
*
* @return true if the reader and writer were successfully set up, or false
* if an error occurred
*/
private boolean initialize() {
Exception exception = null;
try {
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// set up the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
// set up the writer and associate it with the output file
writer = new ImageWriter();
writer.setMetadataRetrieve(omexml);
writer.setInterleaved(reader.isInterleaved());
writer.setId(outputFile);
} catch (FormatException e) {
exception = e;
} catch (IOException e) {
exception = e;
} catch (DependencyException e) {
exception = e;
} catch (ServiceException e) {
exception = e;
}
if (exception != null) {
System.err.println("Failed to initialize files.");
exception.printStackTrace();
}
return exception == null;
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FileExportSPW method export.
/**
* Save a single uint16 plane of data.
*/
public void export() {
int width = 4, height = 4;
int pixelType = FormatTools.UINT16;
Exception exception = null;
IMetadata omexml = initializeMetadata(width, height, pixelType);
int series = 0;
int nSeries = rows * cols * fovPerWell;
// only save data if the file writer was initialized successfully
boolean initializationSuccess = initializeWriter(omexml);
if (initializationSuccess) {
while (series < nSeries) {
for (int p = 0; p < sizeT; p++) {
savePlane(width, height, pixelType, p, series);
}
series++;
if (series < nSeries) {
try {
writer.setSeries(series);
} catch (FormatException e) {
System.err.println("Fatal error unable to select correct image in series! " + e.getMessage());
break;
}
}
}
// endwhile
}
// endif
cleanup();
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class OverlappedTiledWriter method initialize.
/**
* Set up the file reader and writer, ensuring that the input file is
* associated with the reader and the output file is associated with the
* writer.
*
* @return true if the reader and writer were successfully set up, or false
* if an error occurred
* @throws DependencyException thrown if failed to create an OMEXMLService
* @throws IOException thrown if unable to setup input or output stream for reader or writer
* @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
* @throws ServiceException thrown if unable to create OME-XML meta data
*/
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// set up the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
// set up the writer and associate it with the output file
writer = new OMETiffWriter();
writer.setMetadataRetrieve(omexml);
writer.setInterleaved(reader.isInterleaved());
// set the tile size height and width for writing
this.tileSizeX = writer.setTileSizeX(tileSizeX);
this.tileSizeY = writer.setTileSizeY(tileSizeY);
writer.setId(outputFile);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class writeMapAnnotationsExample method main.
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Please specify an output file name.");
System.exit(1);
}
String id = args[0];
// create blank 512x512 image
System.out.println("Creating random image...");
int w = 512, h = 512, c = 1;
int pixelType = FormatTools.UINT16;
byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
// fill with random data
for (int i = 0; i < img.length; i++) img[i] = (byte) (256 * Math.random());
// Create MapPair Object and add to List
List<MapPair> mapList = new ArrayList<MapPair>();
mapList.add(new MapPair("Example Key", "Example Value"));
mapList.add(new MapPair("Bio-Formats Version", FormatTools.VERSION));
// create metadata object with minimum required metadata fields
System.out.println("Populating metadata...");
// add (minimum+Map)Annotations to the metadata object
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata metadata = service.createOMEXMLMetadata();
metadata.createRoot();
MetadataTools.populateMetadata(metadata, 0, null, false, "XYZCT", FormatTools.getPixelTypeString(pixelType), w, h, 1, c, 1, c);
int mapAnnotationIndex = 0;
int annotationRefIndex = 0;
String mapAnnotationID = MetadataTools.createLSID("MapAnnotation", 0, mapAnnotationIndex);
metadata.setMapAnnotationID(mapAnnotationID, mapAnnotationIndex);
metadata.setMapAnnotationValue(mapList, mapAnnotationIndex);
metadata.setMapAnnotationAnnotator("Example Map Annotation", mapAnnotationIndex);
metadata.setMapAnnotationDescription("Example Description", mapAnnotationIndex);
metadata.setMapAnnotationNamespace("Example NameSpace", mapAnnotationIndex);
metadata.setImageAnnotationRef(mapAnnotationID, 0, annotationRefIndex);
mapAnnotationIndex = 1;
annotationRefIndex = 1;
mapAnnotationID = MetadataTools.createLSID("MapAnnotation", 0, mapAnnotationIndex);
metadata.setMapAnnotationID(mapAnnotationID, mapAnnotationIndex);
metadata.setMapAnnotationValue(mapList, mapAnnotationIndex);
metadata.setMapAnnotationAnnotator("Example Map Annotation 1", mapAnnotationIndex);
metadata.setMapAnnotationDescription("Example Description 1", mapAnnotationIndex);
metadata.setMapAnnotationNamespace("Example NameSpace 1", mapAnnotationIndex);
metadata.setImageAnnotationRef(mapAnnotationID, 0, annotationRefIndex);
// Initialize writer and save file
ImageWriter writer = new ImageWriter();
writer.setMetadataRetrieve(metadata);
writer.setId(id);
writer.saveBytes(0, img);
writer.close();
System.out.println("Done.");
}
Aggregations