예제 #1
0
  public void run(String arg) {
    ImageCheck ic = new ImageCheck();
    if (!ImageCheck.checkEnvironment()) return;
    ImagePlus imp = IJ.getImage();
    if (!ic.isBinary(imp)) {
      IJ.error("8-bit binary (black and white only) image required.");
      return;
    }

    if (!ic.isVoxelIsotropic(imp, 1E-3)) {
      if (IJ.showMessageWithCancel(
          "Anisotropic voxels",
          "This image contains anisotropic voxels, which will\n"
              + "result in incorrect thickness calculation.\n\n"
              + "Consider rescaling your data so that voxels are isotropic\n"
              + "(Image > Scale...).\n\n"
              + "Continue anyway?")) {
      } else return;
    }
    GenericDialog gd = new GenericDialog("Options");
    gd.addCheckbox("Thickness", true);
    gd.addCheckbox("Spacing", false);
    gd.addCheckbox("Graphic Result", true);
    gd.addCheckbox("Use_ROI_Manager", false);
    gd.addCheckbox("Mask thickness map", true);
    gd.addHelp("http://bonej.org/thickness");
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    boolean doThickness = gd.getNextBoolean();
    boolean doSpacing = gd.getNextBoolean();
    boolean doGraphic = gd.getNextBoolean();
    boolean doRoi = gd.getNextBoolean();
    boolean doMask = gd.getNextBoolean();

    long startTime = System.currentTimeMillis();
    String title = stripExtension(imp.getTitle());

    RoiManager roiMan = RoiManager.getInstance();
    // calculate trabecular thickness (Tb.Th)
    if (doThickness) {
      boolean inverse = false;
      ImagePlus impLTC = new ImagePlus();
      if (doRoi && roiMan != null) {
        ImageStack stack = RoiMan.cropStack(roiMan, imp.getStack(), true, 0, 1);
        ImagePlus crop = new ImagePlus(imp.getTitle(), stack);
        crop.setCalibration(imp.getCalibration());
        impLTC = getLocalThickness(crop, inverse, doMask);
      } else impLTC = getLocalThickness(imp, inverse, doMask);
      impLTC.setTitle(title + "_Tb.Th");
      impLTC.setCalibration(imp.getCalibration());
      double[] stats = StackStats.meanStdDev(impLTC);
      insertResults(imp, stats, inverse);
      if (doGraphic && !Interpreter.isBatchMode()) {
        impLTC.show();
        impLTC.setSlice(1);
        impLTC.getProcessor().setMinAndMax(0, stats[2]);
        IJ.run("Fire");
      }
    }
    if (doSpacing) {
      boolean inverse = true;
      ImagePlus impLTCi = new ImagePlus();
      if (doRoi && roiMan != null) {
        ImageStack stack = RoiMan.cropStack(roiMan, imp.getStack(), true, 255, 1);
        ImagePlus crop = new ImagePlus(imp.getTitle(), stack);
        crop.setCalibration(imp.getCalibration());
        impLTCi = getLocalThickness(crop, inverse, doMask);
      } else impLTCi = getLocalThickness(imp, inverse, doMask);
      // check marrow cavity size (i.e. trabcular separation, Tb.Sp)
      impLTCi.setTitle(title + "_Tb.Sp");
      impLTCi.setCalibration(imp.getCalibration());
      double[] stats = StackStats.meanStdDev(impLTCi);
      insertResults(imp, stats, inverse);
      if (doGraphic && !Interpreter.isBatchMode()) {
        impLTCi.show();
        impLTCi.setSlice(1);
        impLTCi.getProcessor().setMinAndMax(0, stats[2]);
        IJ.run("Fire");
      }
    }
    IJ.showProgress(1.0);
    IJ.showStatus("Done");
    double duration = ((double) System.currentTimeMillis() - (double) startTime) / (double) 1000;
    IJ.log("Duration = " + IJ.d2s(duration, 3) + " s");
    UsageReporter.reportEvent(this).send();
    return;
  }
예제 #2
0
 // Delete preferences file when ImageJ quits
 private void reset() {
   if (IJ.showMessageWithCancel(
       "Reset Preferences", "Preferences will be reset when ImageJ restarts."))
     Prefs.resetPreferences();
 }
예제 #3
0
  public void run(String arg) {
    imp = IJ.getImage();
    int stackSize = imp.getStackSize();
    if (imp == null) {
      IJ.noImage();
      return;
    }

    //  Make sure input image is a stack.
    if (stackSize == 1) {
      IJ.error("Z Project", "Stack required");
      return;
    }

    //  Check for inverting LUT.
    if (imp.getProcessor().isInvertedLut()) {
      if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return;
    }

    // Set default bounds.
    int channels = imp.getNChannels();
    int frames = imp.getNFrames();
    int slices = imp.getNSlices();
    isHyperstack =
        imp.isHyperStack()
            || (ij.macro.Interpreter.isBatchMode()
                && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize)));
    boolean simpleComposite = channels == stackSize;
    if (simpleComposite) isHyperstack = false;
    startSlice = 1;
    if (isHyperstack) {
      int nSlices = imp.getNSlices();
      if (nSlices > 1) stopSlice = nSlices;
      else stopSlice = imp.getNFrames();
    } else stopSlice = stackSize;

    // Build control dialog
    GenericDialog gd = buildControlDialog(startSlice, stopSlice);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    if (!imp.lock()) return; // exit if in use
    long tstart = System.currentTimeMillis();
    setStartSlice((int) gd.getNextNumber());
    setStopSlice((int) gd.getNextNumber());
    method = gd.getNextChoiceIndex();
    Prefs.set(METHOD_KEY, method);
    if (isHyperstack) {
      allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false;
      doHyperStackProjection(allTimeFrames);
    } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true);
    else doProjection(true);

    if (arg.equals("") && projImage != null) {
      long tstop = System.currentTimeMillis();
      projImage.setCalibration(imp.getCalibration());
      if (simpleComposite) IJ.run(projImage, "Grays", "");
      projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds");
    }

    imp.unlock();
    IJ.register(ZProjector.class);
    return;
  }