コード例 #1
0
ファイル: Binary.java プロジェクト: kkkkxu/BioImage
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   iterations = (int) gd.getNextNumber();
   count = (int) gd.getNextNumber();
   boolean bb = Prefs.blackBackground;
   Prefs.blackBackground = gd.getNextBoolean();
   if (Prefs.blackBackground != bb) ThresholdAdjuster.update();
   Prefs.padEdges = gd.getNextBoolean();
   EDM.setOutputType(gd.getNextChoiceIndex());
   boolean isInvalid = gd.invalidNumber();
   if (iterations < 1) {
     iterations = 1;
     isInvalid = true;
   }
   if (iterations > MAX_ITERATIONS) {
     iterations = MAX_ITERATIONS;
     isInvalid = true;
   }
   if (count < 1) {
     count = 1;
     isInvalid = true;
   }
   if (count > 8) {
     count = 8;
     isInvalid = true;
   }
   if (isInvalid) return false;
   if (imp != null) {
     operation = gd.getNextChoice();
     arg = operation.toLowerCase();
   }
   return true;
 }
コード例 #2
0
ファイル: Binary.java プロジェクト: kkkkxu/BioImage
 public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
   if (doOptions) {
     this.imp = imp;
     this.pfr = pfr;
     GenericDialog gd = new GenericDialog("Binary Options");
     gd.addNumericField("Iterations (1-" + MAX_ITERATIONS + "):", iterations, 0, 3, "");
     gd.addNumericField("Count (1-8):", count, 0, 3, "");
     gd.addCheckbox("Black background", Prefs.blackBackground);
     gd.addCheckbox("Pad edges when eroding", Prefs.padEdges);
     gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]);
     if (imp != null) {
       gd.addChoice("Do:", operations, operation);
       gd.addPreviewCheckbox(pfr);
       gd.addDialogListener(this);
       previewing = true;
     }
     gd.addHelp(IJ.URL + "/docs/menus/process.html#options");
     gd.showDialog();
     previewing = false;
     if (gd.wasCanceled()) return DONE;
     if (imp == null) { // options dialog only, no do/preview
       dialogItemChanged(gd, null); // read dialog result
       return DONE;
     }
     return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags);
   } else { // no dialog, 'arg' is operation type
     if (!((ByteProcessor) imp.getProcessor()).isBinary()) {
       IJ.error("8-bit binary (black and white only) image required.");
       return DONE;
     }
     return IJ.setupDialog(imp, flags);
   }
 }
コード例 #3
0
ファイル: Selection.java プロジェクト: dannyZhou/imagej
 private void makeBand(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Make Band");
     return;
   }
   Roi roiOrig = roi;
   if (!roi.isArea()) {
     IJ.error("Make Band", "Area selection required");
     return;
   }
   Calibration cal = imp.getCalibration();
   double pixels = bandSize;
   double size = pixels * cal.pixelWidth;
   int decimalPlaces = 0;
   if ((int) size != size) decimalPlaces = 2;
   GenericDialog gd = new GenericDialog("Make Band");
   gd.addNumericField("Band Size:", size, decimalPlaces, 4, cal.getUnits());
   gd.showDialog();
   if (gd.wasCanceled()) return;
   size = gd.getNextNumber();
   if (Double.isNaN(size)) {
     IJ.error("Make Band", "invalid number");
     return;
   }
   int n = (int) Math.round(size / cal.pixelWidth);
   if (n > 255) {
     IJ.error("Make Band", "Cannot make bands wider that 255 pixels");
     return;
   }
   int width = imp.getWidth();
   int height = imp.getHeight();
   Rectangle r = roi.getBounds();
   ImageProcessor ip = roi.getMask();
   if (ip == null) {
     ip = new ByteProcessor(r.width, r.height);
     ip.invert();
   }
   ImageProcessor mask = new ByteProcessor(width, height);
   mask.insert(ip, r.x, r.y);
   ImagePlus edm = new ImagePlus("mask", mask);
   boolean saveBlackBackground = Prefs.blackBackground;
   Prefs.blackBackground = false;
   int saveType = EDM.getOutputType();
   EDM.setOutputType(EDM.BYTE_OVERWRITE);
   IJ.run(edm, "Distance Map", "");
   EDM.setOutputType(saveType);
   Prefs.blackBackground = saveBlackBackground;
   ip = edm.getProcessor();
   ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
   int xx = -1, yy = -1;
   for (int x = r.x; x < r.x + r.width; x++) {
     for (int y = r.y; y < r.y + r.height; y++) {
       if (ip.getPixel(x, y) < n) {
         xx = x;
         yy = y;
         break;
       }
     }
     if (xx >= 0 || yy >= 0) break;
   }
   int count = IJ.doWand(edm, xx, yy, 0, null);
   if (count <= 0) {
     IJ.error("Make Band", "Unable to make band");
     return;
   }
   ShapeRoi roi2 = new ShapeRoi(edm.getRoi());
   if (!(roi instanceof ShapeRoi)) roi = new ShapeRoi(roi);
   ShapeRoi roi1 = (ShapeRoi) roi;
   roi2 = roi2.not(roi1);
   Undo.setup(Undo.ROI, imp);
   transferProperties(roiOrig, roi2);
   imp.setRoi(roi2);
   bandSize = n;
 }