Example #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;
   }
 }
  public boolean resizeImage(Image i, File outputFile, int width, int height) {
    ImagePlus ip = ((ImageJImage) i).getImagePlus();
    ImageProcessor processor = ip.getProcessor();
    processor = processor.resize(width, height);
    ip.setProcessor(null, processor);

    return ImageProcess.save(((ImageJImage) i).getImageType(), ip, outputFile);
  }
  /**
   * Creates a JPEG thumbnail from inputFile and saves it to disk in outputFile. scaleWidth is the
   * width to scale the image to
   */
  public boolean createThumb(Image iw, File outputFile, int size, boolean square)
      throws IOException {
    ImagePlus ip = ((ImageJImage) iw).getImagePlus();
    // Load the input image.
    if (ip == null) {
      return false;
    }
    ip = new ImagePlus(ip.getTitle(), ip.getImageStack());
    ImageProcessor processor = ip.getProcessor();
    if (square) {
      processor = processor.resize(size, size);
    } else if (ip.getWidth() > ip.getHeight()) {
      processor = processor.resize(size, ip.getHeight() * size / ip.getWidth());
    } else {
      processor = processor.resize(ip.getWidth() * size / ip.getHeight(), size);
    }
    ip.setProcessor(null, processor);
    int type = ((ImageJImage) iw).getImageType();

    return ImageProcess.save(type, ip, outputFile);
  }
  /**
   * Resizes the current array to the given dimensions.
   *
   * @param input the array to resize
   * @param lenX the desired length in x-direction (with, horizontal length)
   * @param lenY the desired length in y-direction (height, vertical length)
   * @return a new 2d float array with the specified dimensions, and values interpolated from the
   *     input array.
   */
  public static float[][] resize(float[][] input, int lenX, int lenY) {
    float[] linearized = linearize2DArray(input);

    ImageStack is = ImageStack.create(input.length, input[0].length, 1, 32);
    is.setPixels(linearized, 1);

    ImageProcessor ip = new ImagePlus("", is).getProcessor();
    ip.setInterpolationMethod(ImageProcessor.BICUBIC);
    float[] resized = (float[]) ip.resize(lenX, lenY).getPixels();

    return linearizedArrayTo2D(resized, lenX, lenY);
  }
Example #5
0
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   int nSlices = imp.getStackSize();
   int w = imp.getWidth(), h = imp.getHeight();
   ImagePlus imp2 = imp.createImagePlus();
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   int method = interpolationMethod;
   if (w == 1 || h == 1) method = ImageProcessor.NONE;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolationMethod(method);
     ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   IJ.showProgress(1.0);
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, ((CompositeImage) imp).getMode());
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   if (newDepth > 0 && newDepth != oldDepth)
     imp2 = (new Resizer()).zScale(imp2, newDepth, interpolationMethod);
   if (imp2 != null) {
     imp2.show();
     imp2.changes = true;
   }
 }
Example #6
0
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   int nSlices = imp.getStackSize();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   boolean interp = interpolate;
   if (imp.getWidth() == 1 || imp.getHeight() == 1) interp = false;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolate(interp);
     ip2 = ip1.resize(newWidth, newHeight);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   ImagePlus imp2 = imp.createImagePlus();
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   IJ.showProgress(1.0);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, 0);
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   imp2.show();
   imp2.changes = true;
 }