Esempio n. 1
0
 /** Opens the nth image of the specified TIFF stack. */
 public ImagePlus openTiff(String path, int n) {
   TiffDecoder td = new TiffDecoder(getDir(path), getName(path));
   if (IJ.debugMode) td.enableDebugging();
   FileInfo[] info = null;
   try {
     info = td.getTiffInfo();
   } catch (IOException e) {
     String msg = e.getMessage();
     if (msg == null || msg.equals("")) msg = "" + e;
     IJ.error("Open TIFF", msg);
     return null;
   }
   if (info == null) return null;
   FileInfo fi = info[0];
   if (info.length == 1 && fi.nImages > 1) {
     if (n < 1 || n > fi.nImages)
       throw new IllegalArgumentException("N out of 1-" + fi.nImages + " range");
     long size = fi.width * fi.height * fi.getBytesPerPixel();
     fi.longOffset = fi.getOffset() + (n - 1) * (size + fi.gapBetweenImages);
     fi.offset = 0;
     fi.nImages = 1;
   } else {
     if (n < 1 || n > info.length)
       throw new IllegalArgumentException("N out of 1-" + info.length + " range");
     fi.longOffset = info[n - 1].getOffset();
     fi.offset = 0;
     fi.stripOffsets = info[n - 1].stripOffsets;
     fi.stripLengths = info[n - 1].stripLengths;
   }
   FileOpener fo = new FileOpener(fi);
   return fo.open(false);
 }
Esempio n. 2
0
 /** Deserialize a byte array that was serialized using the FileSaver.serialize(). */
 public ImagePlus deserialize(byte[] bytes) {
   ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
   TiffDecoder decoder = new TiffDecoder(stream, "Untitled");
   if (IJ.debugMode) decoder.enableDebugging();
   FileInfo[] info = null;
   try {
     info = decoder.getTiffInfo();
   } catch (IOException e) {
     return null;
   }
   FileOpener opener = new FileOpener(info[0]);
   ImagePlus imp = opener.open(false);
   if (imp == null) return null;
   imp.setTitle(info[0].fileName);
   imp = makeComposite(imp, info[0]);
   return imp;
 }
Esempio n. 3
0
 ImagePlus openTiff2(FileInfo[] info) {
   if (info == null) return null;
   ImagePlus imp = null;
   if (IJ.debugMode) // dump tiff tags
   IJ.log(info[0].debugInfo);
   if (info.length > 1) { // try to open as stack
     imp = openTiffStack(info);
     if (imp != null) return imp;
   }
   FileOpener fo = new FileOpener(info[0]);
   imp = fo.open(false);
   if (imp == null) return null;
   int[] offsets = info[0].stripOffsets;
   if (offsets != null && offsets.length > 1 && offsets[offsets.length - 1] < offsets[0])
     ij.IJ.run(imp, "Flip Vertically", "stack");
   imp = makeComposite(imp, info[0]);
   if (imp.getBitDepth() == 32 && imp.getTitle().startsWith("FFT of")) return openFFT(imp);
   else return imp;
 }
Esempio n. 4
0
 /** Opens the image and displays it. */
 public void open() {
   open(true);
 }