예제 #1
0
 public void run(ImageProcessor ip) {
   if (enlarge && gd.wasOKed())
     synchronized (this) {
       if (!isEnlarged) {
         enlargeCanvas();
         isEnlarged = true;
       }
     }
   if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel
                     // threads
     int slice = pfr.getSliceNumber();
     if (imp.getStackSize() == 1) ip = imp.getProcessor();
     else ip = imp.getStack().getProcessor(slice);
   }
   ip.setInterpolationMethod(interpolationMethod);
   if (fillWithBackground) {
     Color bgc = Toolbar.getBackgroundColor();
     if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc));
     else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB());
   } else ip.setBackgroundValue(0);
   ip.rotate(angle);
   if (!gd.wasOKed()) drawGridLines(gridLines);
   if (isEnlarged && imp.getStackSize() == 1) {
     imp.changes = true;
     imp.updateAndDraw();
     Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
   }
 }
예제 #2
0
  /**
   * 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);
  }
예제 #3
0
 public void run(String arg) {
   imp = IJ.getImage();
   Roi roi = imp.getRoi();
   if (roi != null && !roi.isArea()) imp.deleteRoi(); // ignore any line selection
   ImageProcessor ip = imp.getProcessor();
   if (!showDialog(ip)) return;
   if (newDepth > 0 && newDepth != oldDepth) {
     newWindow = true;
     processStack = true;
   }
   if ((ip.getWidth() > 1 && ip.getHeight() > 1) || newWindow)
     ip.setInterpolationMethod(interpolationMethod);
   else ip.setInterpolationMethod(ImageProcessor.NONE);
   ip.setBackgroundValue(bgValue);
   imp.startTiming();
   try {
     if (newWindow && imp.getStackSize() > 1 && processStack) createNewStack(imp, ip);
     else scale(ip);
   } catch (OutOfMemoryError o) {
     IJ.outOfMemory("Scale");
   }
   IJ.showProgress(1.0);
 }
예제 #4
0
  /**
   * Combination of {@link ImageJInterpolation#crop(float[][], float, float, float, float)} and
   * {@link ImageJInterpolation#resize(float[][], int, int)}. Crops and resizes the input array into
   * a new output array.
   *
   * @param input the array to work on
   * @param lenX the desired length in x-direction (with, horizontal length)
   * @param lenY the desired length in y-direction (height, vertical length)
   * @param minX the lower index in x-direction
   * @param minY the lower index in y-direction
   * @param maxX the higher index in x-direction
   * @param maxY the higher index in y-direction
   * @return a new cropped and resized version of the input array
   */
  public static float[][] cropAndResize(
      float[][] input, int lenX, int lenY, float minX, float minY, float maxX, float maxY) {

    float[] linearized = linearize2DArray(input);

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

    ImageProcessor ip = new ImagePlus("", is).getProcessor();
    ip.setInterpolationMethod(ImageProcessor.BICUBIC);
    ip.setRoi((int) minX, (int) minY, (int) Math.ceil(maxX - minX), (int) Math.ceil(maxY - minY));

    float[] resized = (float[]) ip.crop().resize(lenX, lenY).getPixels();

    return linearizedArrayTo2D(resized, lenX, lenY);
  }
예제 #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;
   }
 }