use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class SewTiffs method main.
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: java SewTiffs base_name channel_num [time_count]");
System.exit(1);
}
String base = args[0];
int c = Integer.parseInt(args[1]);
int num;
if (args.length < 3) {
FilePattern fp = new FilePattern(new Location(base + "_C" + c + "_TP1.tiff"));
int[] count = fp.getCount();
num = count[count.length - 1];
} else
num = Integer.parseInt(args[2]);
System.out.println("Fixing " + base + "_C" + c + "_TP<1-" + num + ">.tiff");
TiffReader in = new TiffReader();
TiffWriter out = new TiffWriter();
String outId = base + "_C" + c + ".tiff";
System.out.println("Writing " + outId);
out.setId(outId);
System.out.print(" ");
boolean comment = false;
for (int t = 0; t < num; t++) {
String inId = base + "_C" + c + "_TP" + (t + 1) + ".tiff";
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
in.setMetadataStore(meta);
in.setId(inId);
out.setMetadataRetrieve(meta);
// read first image plane
byte[] image = in.openBytes(0);
in.close();
if (t == 0) {
// read first IFD
RandomAccessInputStream ras = new RandomAccessInputStream(inId);
TiffParser parser = new TiffParser(ras);
IFD ifd = parser.getFirstIFD();
ras.close();
// preserve TIFF comment
String desc = ifd.getComment();
if (desc != null) {
ifd = new IFD();
ifd.putIFDValue(IFD.IMAGE_DESCRIPTION, desc);
comment = true;
out.saveBytes(t, image, ifd);
System.out.print(".");
continue;
}
}
// write image plane
out.saveBytes(t, image);
// update status
System.out.print(".");
if (t % DOTS == DOTS - 1) {
System.out.println(" " + (t + 1));
System.out.print(" ");
}
}
System.out.println();
if (comment)
System.out.println("OME-TIFF comment saved.");
else
System.out.println("No OME-TIFF comment found.");
}
Aggregations