Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    if (imp == null) {
      IJ.noImage();
      return;
    }

    ImageStack stack1 = imp.getStack();
    String fileName = imp.getTitle();
    int endslice = stack1.getSize();

    ImagePlus imp2 = duplicateStack(imp);
    imp2.show();
    String duplicateName = imp2.getTitle();
    // IJ.showMessage("Box",fileName);
    ImageStack stack2 = imp2.getStack();
    stack1.deleteSlice(1);
    stack2.deleteSlice(endslice);

    String calculatorstring =
        ("image1='"
            + fileName
            + "' operation=Subtract image2="
            + imp2.getTitle()
            + " create stack");

    IJ.run("Image Calculator...", calculatorstring);
    ImagePlus imp3 = WindowManager.getCurrentImage();
    imp3.setTitle(fileName + " DeltaF up");
    imp2.getWindow().close();
    imp.getWindow().close();
  }
 /**
  * Execute plugin functionality: stack FFT with window function, max projection over all slices
  * (phase, Z angle), blank out central 1/8 circle (set to min value), display min-max.
  */
 public ResultSet exec(ImagePlus... imps) {
   ImagePlus imp = imps[0];
   Util_StackFFT2D stackFFT2D = new Util_StackFFT2D();
   stackFFT2D.resultTypeChoice = Util_StackFFT2D.resultType[1];
   ImagePlus impF = stackFFT2D.exec(imp);
   IJ.run(impF, "Z Project...", "projection=[Max Intensity]");
   ImagePlus impProjF = ij.WindowManager.getCurrentImage();
   maskCentralRegion(impProjF);
   if (impProjF.isComposite()) {
     // display grayscale, not colored composite
     CompositeImage ci = (CompositeImage) impProjF;
     ci.setMode(IJ.GRAYSCALE);
     impProjF.updateAndDraw();
   }
   displayMinToMax(impProjF);
   impProjF.setTitle(I1l.makeTitle(imps[0], TLA));
   String shortInfo =
       "Maximum intensity projection of log"
           + " (amplitude^2) 2D FFT stack, central region masked,"
           + " rescaled (min-max) to improve contrast of the relevant"
           + " frequency range.";
   results.addImp(shortInfo, impProjF);
   results.addInfo(
       "How to interpret",
       "look for clean 1st & 2nd"
           + " order spots, similar across angles. Note that spot"
           + " intensity depends on image content.");
   return results;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 void flatten() {
   ImagePlus imp = IJ.getImage();
   ImagePlus imp2 = imp.flatten();
   imp2.setTitle(WindowManager.getUniqueName(imp.getTitle()));
   imp2.show();
 }
  public void run(ImageProcessor ip) {
    String[] imageNames = getOpenImageNames();
    if (imageNames[0] == "None") {
      IJ.error("need at least 2 binary open images");
      return;
    }
    double previousMinOverlap = Prefs.get("BVTB.BinaryFeatureExtractor.minOverlap", 0);
    boolean previousCombine = Prefs.get("BVTB.BinaryFeatureExtractor.combine", false);

    GenericDialog gd = new GenericDialog("Binary Feature Extractor");
    gd.addChoice("Objects image", imageNames, imageNames[0]);
    gd.addChoice("Selector image", imageNames, imageNames[1]);
    gd.addNumericField("Object_overlap in % (0=off)", previousMinOverlap, 0, 9, "");
    gd.addCheckbox("Combine objects and selectors", previousCombine);
    gd.addCheckbox("Count output", true);
    gd.addCheckbox("Analysis tables", false);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    String objectsImgTitle = gd.getNextChoice();
    String selectorsImgTitle = gd.getNextChoice();
    double minOverlap = gd.getNextNumber();
    boolean combineImages = gd.getNextBoolean();
    boolean showCountOutput = gd.getNextBoolean();
    boolean showAnalysis = gd.getNextBoolean();
    if (gd.invalidNumber() || minOverlap < 0 || minOverlap > 100) {
      IJ.error("invalid number");
      return;
    }
    Prefs.set("BVTB.BinaryFeatureExtractor.minOverlap", minOverlap);
    Prefs.set("BVTB.BinaryFeatureExtractor.combine", combineImages);

    if (objectsImgTitle.equals(selectorsImgTitle)) {
      IJ.error("images need to be different");
      return;
    }

    ImagePlus objectsImp = WindowManager.getImage(objectsImgTitle);
    ImageProcessor objectsIP = objectsImp.getProcessor();
    ImagePlus selectorsImp = WindowManager.getImage(selectorsImgTitle);
    ImageProcessor selectorsIP = selectorsImp.getProcessor();

    if (!objectsIP.isBinary() || !selectorsIP.isBinary()) {
      IJ.error("works with 8-bit binary images only");
      return;
    }

    if ((objectsImp.getWidth() != selectorsImp.getWidth())
        || objectsImp.getHeight() != selectorsImp.getHeight()) {
      IJ.error("images need to be of the same size");
      return;
    }

    // close any existing RoiManager before instantiating a new one for this analysis
    RoiManager oldRM = RoiManager.getInstance2();
    if (oldRM != null) {
      oldRM.close();
    }

    RoiManager objectsRM = new RoiManager(true);
    ResultsTable objectsRT = new ResultsTable();
    ParticleAnalyzer analyzeObjects =
        new ParticleAnalyzer(analyzerOptions, measurementFlags, objectsRT, 0.0, 999999999.9);
    analyzeObjects.setRoiManager(objectsRM);

    analyzeObjects.analyze(objectsImp);
    objectsRM.runCommand("Show None");
    int objectNumber = objectsRT.getCounter();

    Roi[] objectRoi = objectsRM.getRoisAsArray();

    ResultsTable measureSelectorsRT = new ResultsTable();
    Analyzer overlapAnalyzer = new Analyzer(selectorsImp, measurementFlags, measureSelectorsRT);

    ImagePlus outputImp =
        IJ.createImage("output", "8-bit black", objectsImp.getWidth(), objectsImp.getHeight(), 1);
    ImageProcessor outputIP = outputImp.getProcessor();

    double[] measuredOverlap = new double[objectNumber];

    outputIP.setValue(255.0);
    for (int o = 0; o < objectNumber; o++) {
      selectorsImp.killRoi();
      selectorsImp.setRoi(objectRoi[o]);
      overlapAnalyzer.measure();
      measuredOverlap[o] = measureSelectorsRT.getValue("%Area", o);
      if (minOverlap != 0.0 && measuredOverlap[o] >= minOverlap) {
        outputIP.fill(objectRoi[o]);
        finalCount++;
      } else if (minOverlap == 0.0 && measuredOverlap[o] > 0.0) {
        outputIP.fill(objectRoi[o]);
        finalCount++;
      }
    }
    // measureSelectorsRT.show("Objects");

    selectorsImp.killRoi();
    RoiManager selectorRM = new RoiManager(true);
    ResultsTable selectorRT = new ResultsTable();
    ParticleAnalyzer.setRoiManager(selectorRM);
    ParticleAnalyzer analyzeSelectors =
        new ParticleAnalyzer(analyzerOptions, measurementFlags, selectorRT, 0.0, 999999999.9);
    analyzeSelectors.analyze(selectorsImp);
    selectorRM.runCommand("Show None");
    int selectorNumber = selectorRT.getCounter();

    if (combineImages) {
      outputImp.updateAndDraw();
      Roi[] selectorRoi = selectorRM.getRoisAsArray();

      ResultsTable measureObjectsRT = new ResultsTable();
      Analyzer selectorAnalyzer = new Analyzer(outputImp, measurementFlags, measureObjectsRT);

      double[] selectorOverlap = new double[selectorNumber];
      outputIP.setValue(255.0);
      for (int s = 0; s < selectorNumber; s++) {
        outputImp.killRoi();
        outputImp.setRoi(selectorRoi[s]);
        selectorAnalyzer.measure();
        selectorOverlap[s] = measureObjectsRT.getValue("%Area", s);
        if (selectorOverlap[s] > 0.0d) {
          outputIP.fill(selectorRoi[s]);
        }
      }
      selectorRoi = null;
      selectorAnalyzer = null;
      measureObjectsRT = null;
    }
    // selectorRT.show("Selectors");
    outputImp.killRoi();
    String outputImageTitle = WindowManager.getUniqueName("Extracted_" + objectsImgTitle);
    outputImp.setTitle(outputImageTitle);
    outputImp.show();
    outputImp.changes = true;

    if (showCountOutput) {
      String[] openTextWindows = WindowManager.getNonImageTitles();
      boolean makeNewTable = true;
      for (int w = 0; w < openTextWindows.length; w++) {
        if (openTextWindows[w].equals("BFE_Results")) {
          makeNewTable = false;
        }
      }

      TextWindow existingCountTable = ResultsTable.getResultsWindow();
      if (makeNewTable) {
        countTable = new ResultsTable();
        countTable.setPrecision(0);
        countTable.setValue("Image", 0, outputImageTitle);
        countTable.setValue("Objects", 0, objectNumber);
        countTable.setValue("Selectors", 0, selectorNumber);
        countTable.setValue("Extracted", 0, finalCount);
        countTable.show("BFE_Results");
      } else {
        IJ.renameResults("BFE_Results", "Results");
        countTable = ResultsTable.getResultsTable();
        countTable.setPrecision(0);
        countTable.incrementCounter();
        countTable.addValue("Image", outputImageTitle);
        countTable.addValue("Objects", objectNumber);
        countTable.addValue("Selectors", selectorNumber);
        countTable.addValue("Extracted", finalCount);
        IJ.renameResults("Results", "BFE_Results");
        countTable.show("BFE_Results");
      }
    }

    if (showAnalysis) {
      ResultsTable extractedRT = new ResultsTable();
      ParticleAnalyzer analyzeExtracted =
          new ParticleAnalyzer(
              ParticleAnalyzer.CLEAR_WORKSHEET | ParticleAnalyzer.RECORD_STARTS,
              measurementFlags,
              extractedRT,
              0.0,
              999999999.9);
      analyzeExtracted.analyze(outputImp);
      objectsRT.show("Objects");
      selectorRT.show("Selectors");
      extractedRT.show("Extracted");
    } else {
      objectsRT = null;
      selectorRT = null;
    }

    objectsRM = null;
    measureSelectorsRT = null;
    analyzeObjects = null;
    overlapAnalyzer = null;
    objectRoi = null;
    selectorRM = null;

    objectsImp.killRoi();
    objectsImp.changes = false;
    selectorsImp.changes = false;
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
 void setMagnification2(double magnification) {
   if (magnification > 32.0) magnification = 32.0;
   if (magnification < 0.03125) magnification = 0.03125;
   this.magnification = magnification;
   imp.setTitle(imp.getTitle());
 }