Changeset 3168 for trunk


Ignore:
Timestamp:
09/17/07 16:16:02 (12 years ago)
Author:
curtis
Message:

Update OME-TIFF conversion program to use most current API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/ConvertToOmeTiff.java

    r3121 r3168  
    44 
    55import java.awt.image.BufferedImage; 
    6 import java.util.Hashtable; 
    7 import loci.formats.*; 
     6import loci.formats.ImageReader; 
    87import loci.formats.ome.OMEXMLMetadata; 
    9 import loci.formats.out.TiffWriter; 
     8import loci.formats.out.OMETiffWriter; 
    109 
    1110/** Converts the given files to OME-TIFF format. */ 
     
    1817    } 
    1918    ImageReader reader = new ImageReader(); 
    20     TiffWriter writer = new TiffWriter(); 
    21     // record metadata to OME-XML format 
    22     OMEXMLMetadata omexmlMeta = new OMEXMLMetadata(); 
    23     reader.setMetadataStore(omexmlMeta); 
     19    OMETiffWriter writer = new OMETiffWriter(); 
    2420    for (int i=0; i<args.length; i++) { 
    2521      String id = args[i]; 
    26       String outId = id + ".tif"; 
     22      int dot = id.indexOf("."); 
     23      String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif"; 
    2724      System.out.print("Converting " + id + " to " + outId + " "); 
     25 
     26      // record metadata to OME-XML format 
     27      OMEXMLMetadata omexmlMeta = new OMEXMLMetadata(); 
     28      reader.setMetadataStore(omexmlMeta); 
    2829      reader.setId(id);  
     30 
     31      // configure OME-TIFF writer 
     32      writer.setMetadataRetrieve(omexmlMeta); 
     33      writer.setId(outId); 
     34 
     35      // write out image planes 
    2936      int imageCount = reader.getImageCount(); 
    30       // insert TiffData element into OME-XML 
    31       // currently handles only single series (single Image, single Pixels) 
    32       String xml = omexmlMeta.dumpXML(); 
    33       int pix = xml.indexOf("<Pixels "); 
    34       int end = xml.indexOf("/>", pix); 
    35       xml = xml.substring(0, end) + 
    36         "><TiffData/></Pixels>" + xml.substring(end + 2); 
    37       // write out image planes 
    3837      for (int j=0; j<imageCount; j++) { 
    3938        BufferedImage plane = reader.openImage(j); 
    40         Hashtable ifd = null; 
    41         if (j == 0) { 
    42           // save OME-XML metadata to TIFF file's first IFD 
    43           ifd = new Hashtable(); 
    44           TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION, xml); 
    45         } 
    4639        // write plane to output file 
    47         writer.setId(outId); 
    48         writer.saveImage(plane, ifd, j == imageCount - 1); 
     40        writer.saveImage(plane, j == imageCount - 1); 
    4941        System.out.print("."); 
    5042      } 
     43      writer.close(); 
     44      reader.close(); 
    5145      System.out.println(" [done]"); 
    5246    } 
Note: See TracChangeset for help on using the changeset viewer.