Exemplo n.º 1
0
 void scale(ImageProcessor ip) {
   if (newWindow) {
     Rectangle r = ip.getRoi();
     ImagePlus imp2 = imp.createImagePlus();
     imp2.setProcessor(title, ip.resize(newWidth, newHeight, averageWhenDownsizing));
     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.deleteRoi();
     imp.updateAndDraw();
     imp.changes = true;
   }
 }
Exemplo n.º 2
0
 /**
  * Creates a dialog box, allowing the user to enter the requested width, height, x & y
  * coordinates, slice number for a Region Of Interest, option for oval, and option for whether x &
  * y coordinates to be centered.
  */
 void showDialog() {
   Calibration cal = imp.getCalibration();
   int digits = 0;
   if (scaledUnits && cal.scaled()) digits = 2;
   Roi roi = imp.getRoi();
   if (roi == null) drawRoi();
   GenericDialog gd = new GenericDialog("Specify");
   gd.addNumericField("Width:", width, digits);
   gd.addNumericField("Height:", height, digits);
   gd.addNumericField("X coordinate:", xRoi, digits);
   gd.addNumericField("Y coordinate:", yRoi, digits);
   if (stackSize > 1) gd.addNumericField("Slice:", iSlice, 0);
   gd.addCheckbox("Oval", oval);
   gd.addCheckbox("Constrain square/circle", square);
   gd.addCheckbox("Centered", centered);
   if (cal.scaled()) {
     boolean unitsMatch = cal.getXUnit().equals(cal.getYUnit());
     String units = unitsMatch ? cal.getUnits() : cal.getXUnit() + " x " + cal.getYUnit();
     gd.addCheckbox("Scaled units (" + units + ")", scaledUnits);
   }
   fields = gd.getNumericFields();
   gd.addDialogListener(this);
   gd.showDialog();
   if (gd.wasCanceled()) {
     if (roi == null) imp.deleteRoi();
     else // *ALWAYS* restore initial ROI when cancelled
     imp.setRoi(roi);
   }
 }
Exemplo n.º 3
0
 private boolean deleteOverlayRoi(ImagePlus imp) {
   if (imp == null) return false;
   Overlay overlay = null;
   ImageCanvas ic = imp.getCanvas();
   if (ic != null) overlay = ic.getShowAllList();
   if (overlay == null) overlay = imp.getOverlay();
   if (overlay == null) return false;
   Roi roi = imp.getRoi();
   for (int i = 0; i < overlay.size(); i++) {
     Roi roi2 = overlay.get(i);
     if (roi2 == roi) {
       overlay.remove(i);
       imp.deleteRoi();
       ic = imp.getCanvas();
       if (ic != null) ic.roiManagerSelect(roi, true);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
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);
 }