Пример #1
0
 void scale(ImageProcessor ip) {
   if (newWindow) {
     Rectangle r = ip.getRoi();
     ImagePlus imp2 = imp.createImagePlus();
     imp2.setProcessor(title, ip.resize(newWidth, newHeight));
     Calibration cal = imp2.getCalibration();
     if (cal.scaled()) {
       cal.pixelWidth *= 1.0 / xscale;
       cal.pixelHeight *= 1.0 / yscale;
     }
     imp2.show();
     imp.trimProcessor();
     imp2.trimProcessor();
     imp2.changes = true;
   } else {
     if (processStack && imp.getStackSize() > 1) {
       Undo.reset();
       StackProcessor sp = new StackProcessor(imp.getStack(), ip);
       sp.scale(xscale, yscale, bgValue);
     } else {
       ip.snapshot();
       Undo.setup(Undo.FILTER, imp);
       ip.setSnapshotCopyMode(true);
       ip.scale(xscale, yscale);
       ip.setSnapshotCopyMode(false);
     }
     imp.killRoi();
     imp.updateAndDraw();
     imp.changes = true;
   }
 }
Пример #2
0
  /** Restores original disk or network version of image. */
  public void revertToSaved(ImagePlus imp) {
    Image img;
    ProgressBar pb = IJ.getInstance().getProgressBar();
    ImageProcessor ip;
    String path = fi.directory + fi.fileName;

    if (fi.fileFormat == fi.GIF_OR_JPG) {
      // restore gif or jpg
      img = Toolkit.getDefaultToolkit().createImage(path);
      imp.setImage(img);
      if (imp.getType() == ImagePlus.COLOR_RGB) Opener.convertGrayJpegTo8Bits(imp);
      return;
    }

    if (fi.fileFormat == fi.DICOM) {
      // restore DICOM
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.DICOM", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.BMP) {
      // restore BMP
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.BMP_Reader", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.PGM) {
      // restore PGM
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.PGM_Reader", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.ZIP_ARCHIVE) {
      // restore ".zip" file
      ImagePlus imp2 = (new Opener()).openZip(path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    // restore PNG or another image opened using ImageIO
    if (fi.fileFormat == fi.IMAGEIO) {
      ImagePlus imp2 = (new Opener()).openUsingImageIO(path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.nImages > 1) return;

    ColorModel cm;
    if (fi.url == null || fi.url.equals("")) IJ.showStatus("Loading: " + path);
    else IJ.showStatus("Loading: " + fi.url + fi.fileName);
    Object pixels = readPixels(fi);
    if (pixels == null) return;
    cm = createColorModel(fi);
    switch (fi.fileType) {
      case FileInfo.GRAY8:
      case FileInfo.COLOR8:
      case FileInfo.BITMAP:
        ip = new ByteProcessor(width, height, (byte[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.GRAY16_SIGNED:
      case FileInfo.GRAY16_UNSIGNED:
      case FileInfo.GRAY12_UNSIGNED:
        ip = new ShortProcessor(width, height, (short[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.GRAY32_INT:
      case FileInfo.GRAY32_FLOAT:
        ip = new FloatProcessor(width, height, (float[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.RGB:
      case FileInfo.BGR:
      case FileInfo.ARGB:
      case FileInfo.ABGR:
      case FileInfo.RGB_PLANAR:
        img =
            Toolkit.getDefaultToolkit()
                .createImage(new MemoryImageSource(width, height, (int[]) pixels, 0, width));
        imp.setImage(img);
        break;
    }
  }