void showResults() {
   int count = rt.getCounter();
   // if (count==0) return;
   boolean lastSlice = !processStack || slice == imp.getStackSize();
   if ((showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS) && slice == 1 && count > 0)
     imp.setOverlay(overlay);
   else if (outlines != null && lastSlice) {
     String title = imp != null ? imp.getTitle() : "Outlines";
     String prefix;
     if (showChoice == MASKS) prefix = "Mask of ";
     else if (showChoice == ROI_MASKS) prefix = "Count Masks of ";
     else prefix = "Drawing of ";
     outlines.update(drawIP);
     outputImage = new ImagePlus(prefix + title, outlines);
     if (inSituShow) {
       if (imp.getStackSize() == 1) Undo.setup(Undo.TRANSFORM, imp);
       imp.setStack(null, outputImage.getStack());
     } else if (!hideOutputImage) outputImage.show();
   }
   if (showResults && !processStack) {
     TextPanel tp = IJ.getTextPanel();
     if (beginningCount > 0 && tp != null && tp.getLineCount() != count) rt.show("Results");
     Analyzer.firstParticle = beginningCount;
     Analyzer.lastParticle = Analyzer.getCounter() - 1;
   } else Analyzer.firstParticle = Analyzer.lastParticle = 0;
 }
Beispiel #2
0
 public void reduceHyperstack(ImagePlus imp, int factor, boolean reduceSlices) {
   int channels = imp.getNChannels();
   int slices = imp.getNSlices();
   int frames = imp.getNFrames();
   int zfactor = reduceSlices ? factor : 1;
   int tfactor = reduceSlices ? 1 : factor;
   ImageStack stack = imp.getStack();
   ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight());
   boolean virtual = stack.isVirtual();
   int slices2 = slices / zfactor + ((slices % zfactor) != 0 ? 1 : 0);
   int frames2 = frames / tfactor + ((frames % tfactor) != 0 ? 1 : 0);
   int n = channels * slices2 * frames2;
   int count = 1;
   for (int t = 1; t <= frames; t += tfactor) {
     for (int z = 1; z <= slices; z += zfactor) {
       for (int c = 1; c <= channels; c++) {
         int i = imp.getStackIndex(c, z, t);
         IJ.showProgress(i, n);
         ImageProcessor ip = stack.getProcessor(imp.getStackIndex(c, z, t));
         // IJ.log(count++ +"  "+i+" "+c+" "+z+" "+t);
         stack2.addSlice(stack.getSliceLabel(i), ip);
       }
     }
   }
   imp.setStack(stack2, channels, slices2, frames2);
   Calibration cal = imp.getCalibration();
   if (cal.scaled()) cal.pixelDepth *= zfactor;
   if (virtual) imp.setTitle(imp.getTitle());
   IJ.showProgress(1.0);
 }
Beispiel #3
0
 public void reduceStack(ImagePlus imp, int factor) {
   ImageStack stack = imp.getStack();
   boolean virtual = stack.isVirtual();
   int n = stack.getSize();
   ImageStack stack2 = new ImageStack(stack.getWidth(), stack.getHeight());
   for (int i = 1; i <= n; i += factor) {
     if (virtual) IJ.showProgress(i, n);
     stack2.addSlice(stack.getSliceLabel(i), stack.getProcessor(i));
   }
   imp.setStack(null, stack2);
   if (virtual) {
     IJ.showProgress(1.0);
     imp.setTitle(imp.getTitle());
   }
   Calibration cal = imp.getCalibration();
   if (cal.scaled()) cal.pixelDepth *= factor;
 }
Beispiel #4
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;
   }
 }
Beispiel #5
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;
 }
  public void run(String arg) {
    int wOld, hOld, wNew, hNew;
    boolean fIsStack = false;

    ImagePlus imp = IJ.getImage();
    wOld = imp.getWidth();
    hOld = imp.getHeight();

    ImageStack stackOld = imp.getStack();
    if ((stackOld != null) && (stackOld.getSize() > 1)) fIsStack = true;

    String[] sPositions = {
      "Top-Left", "Top-Center", "Top-Right",
      "Center-Left", "Center", "Center-Right",
      "Bottom-Left", "Bottom-Center", "Bottom-Right"
    };

    String strTitle = fIsStack ? "Resize Stack Canvas" : "Resize Image Canvas";
    GenericDialog gd = new GenericDialog(strTitle);
    gd.addNumericField("Width:", wOld, 0, 5, "pixels");
    gd.addNumericField("Height:", hOld, 0, 5, "pixels");
    gd.addChoice("Position:", sPositions, sPositions[4]);
    gd.addCheckbox("Zero Fill", zeroFill);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    wNew = (int) gd.getNextNumber();
    hNew = (int) gd.getNextNumber();
    int iPos = gd.getNextChoiceIndex();
    zeroFill = gd.getNextBoolean();
    Prefs.set("resizer.zero", zeroFill);

    int xOff, yOff;
    int xC = (wNew - wOld) / 2; // offset for centered
    int xR = (wNew - wOld); // offset for right
    int yC = (hNew - hOld) / 2; // offset for centered
    int yB = (hNew - hOld); // offset for bottom

    switch (iPos) {
      case 0: // TL
        xOff = 0;
        yOff = 0;
        break;
      case 1: // TC
        xOff = xC;
        yOff = 0;
        break;
      case 2: // TR
        xOff = xR;
        yOff = 0;
        break;
      case 3: // CL
        xOff = 0;
        yOff = yC;
        break;
      case 4: // C
        xOff = xC;
        yOff = yC;
        break;
      case 5: // CR
        xOff = xR;
        yOff = yC;
        break;
      case 6: // BL
        xOff = 0;
        yOff = yB;
        break;
      case 7: // BC
        xOff = xC;
        yOff = yB;
        break;
      case 8: // BR
        xOff = xR;
        yOff = yB;
        break;
      default: // center
        xOff = xC;
        yOff = yC;
        break;
    }

    if (fIsStack) {
      ImageStack stackNew = expandStack(stackOld, wNew, hNew, xOff, yOff);
      imp.setStack(null, stackNew);
    } else {
      if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER, imp);
      ImageWindow win = imp.getWindow();
      if (win != null && (win instanceof PlotWindow)) ((PlotWindow) win).getPlot().setFrozen(true);
      ImageProcessor newIP = expandImage(imp.getProcessor(), wNew, hNew, xOff, yOff);
      imp.setProcessor(null, newIP);
      if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
    }
    Overlay overlay = imp.getOverlay();
    if (overlay != null) overlay.translate(xOff, yOff);
  }