Example #1
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   Undo.setup(Undo.ROI, imp);
   Roi roi2 = null;
   if (roi.getType() == Roi.LINE) {
     double width = roi.getStrokeWidth();
     if (width <= 1.0) roi.setStrokeWidth(1.0000001);
     FloatPolygon p = roi.getFloatPolygon();
     roi.setStrokeWidth(width);
     roi2 = new PolygonRoi(p, Roi.POLYGON);
     roi2.setDrawOffset(roi.getDrawOffset());
   } else {
     ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
     ip2.setColor(255);
     roi.drawPixels(ip2);
     // new ImagePlus("ip2", ip2.duplicate()).show();
     ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
     ThresholdToSelection tts = new ThresholdToSelection();
     roi2 = tts.convert(ip2);
   }
   transferProperties(roi, roi2);
   roi2.setStrokeWidth(0);
   Color c = roi2.getStrokeColor();
   if (c != null) // remove any transparency
   roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue()));
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
Example #2
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() == 1) {
     IJ.error("Line to Area", "Straight line width must be > 1");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE) ip2.fillPolygon(roi.getPolygon());
   else {
     roi.drawPixels(ip2);
     // BufferedImage bi = new BufferedImage(imp.getWidth(), imp.getHeight(),
     // BufferedImage.TYPE_BYTE_GRAY);
     // Graphics g = bi.getGraphics();
     // Roi roi2 = (Roi)roi.clone();
     // roi2.setStrokeColor(Color.white);
     // roi2.drawOverlay(g);
     // ip2 = new ByteProcessor(bi);
   }
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
Example #3
0
 void createEllipse(ImagePlus imp) {
   IJ.showStatus("Fitting ellipse");
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Fit Ellipse");
     return;
   }
   if (roi.isLine()) {
     IJ.error("Fit Ellipse", "\"Fit Ellipse\" does not work with line selections");
     return;
   }
   ImageProcessor ip = imp.getProcessor();
   ip.setRoi(roi);
   int options = Measurements.CENTROID + Measurements.ELLIPSE;
   ImageStatistics stats = ImageStatistics.getStatistics(ip, options, null);
   double dx = stats.major * Math.cos(stats.angle / 180.0 * Math.PI) / 2.0;
   double dy = -stats.major * Math.sin(stats.angle / 180.0 * Math.PI) / 2.0;
   double x1 = stats.xCentroid - dx;
   double x2 = stats.xCentroid + dx;
   double y1 = stats.yCentroid - dy;
   double y2 = stats.yCentroid + dy;
   double aspectRatio = stats.minor / stats.major;
   imp.killRoi();
   imp.setRoi(new EllipseRoi(x1, y1, x2, y2, aspectRatio));
 }
Example #4
0
  /** Generate output image whose type is same as input image. */
  private ImagePlus makeOutputImage(ImagePlus imp, FloatProcessor fp, int ptype) {
    int width = imp.getWidth();
    int height = imp.getHeight();
    float[] pixels = (float[]) fp.getPixels();
    ImageProcessor oip = null;

    // Create output image consistent w/ type of input image.
    int size = pixels.length;
    switch (ptype) {
      case BYTE_TYPE:
        oip = imp.getProcessor().createProcessor(width, height);
        byte[] pixels8 = (byte[]) oip.getPixels();
        for (int i = 0; i < size; i++) pixels8[i] = (byte) pixels[i];
        break;
      case SHORT_TYPE:
        oip = imp.getProcessor().createProcessor(width, height);
        short[] pixels16 = (short[]) oip.getPixels();
        for (int i = 0; i < size; i++) pixels16[i] = (short) pixels[i];
        break;
      case FLOAT_TYPE:
        oip = new FloatProcessor(width, height, pixels, null);
        break;
    }

    // Adjust for display.
    // Calling this on non-ByteProcessors ensures image
    // processor is set up to correctly display image.
    oip.resetMinAndMax();

    // Create new image plus object. Don't use
    // ImagePlus.createImagePlus here because there may be
    // attributes of input image that are not appropriate for
    // projection.
    return new ImagePlus(makeTitle(), oip);
  }
Example #5
0
 void skeletonize(ImageProcessor ip) {
   if (Prefs.blackBackground) ip.invert();
   boolean edgePixels = hasEdgePixels(ip);
   ImageProcessor ip2 = expand(ip, edgePixels);
   ((ByteProcessor) ip2).skeletonize();
   ip = shrink(ip, ip2, edgePixels);
   if (Prefs.blackBackground) ip.invert();
 }
 /**
  * Updates this stack so its attributes, such as min, max, calibration table and color model, are
  * the same as 'ip'.
  */
 public void update(ImageProcessor ip) {
   if (ip != null) {
     min = ip.getMin();
     max = ip.getMax();
     cTable = ip.getCalibrationTable();
     cm = ip.getColorModel();
   }
 }
Example #7
0
 /** Constructs a Wand object from an ImageProcessor. */
 public Wand(ImageProcessor ip) {
   this.ip = ip;
   if (ip instanceof ByteProcessor) bpixels = (byte[]) ip.getPixels();
   else if (ip instanceof ColorProcessor) cpixels = (int[]) ip.getPixels();
   else if (ip instanceof ShortProcessor) spixels = (short[]) ip.getPixels();
   else if (ip instanceof FloatProcessor) fpixels = (float[]) ip.getPixels();
   width = ip.getWidth();
   height = ip.getHeight();
 }
Example #8
0
 ImageProcessor shrink(ImageProcessor ip, ImageProcessor ip2, boolean hasEdgePixels) {
   if (hasEdgePixels) {
     int width = ip.getWidth();
     int height = ip.getHeight();
     for (int y = 0; y < height; y++)
       for (int x = 0; x < width; x++) ip.putPixel(x, y, ip2.getPixel(x + 1, y + 1));
   }
   return ip;
 }
Example #9
0
 /** Draws an outline of this OvalRoi on the image. */
 public void drawPixels(ImageProcessor ip) {
   Polygon p = getPolygon();
   if (p.npoints > 0) {
     int saveWidth = ip.getLineWidth();
     if (getStrokeWidth() > 1f) ip.setLineWidth((int) Math.round(getStrokeWidth()));
     ip.drawPolygon(p);
     ip.setLineWidth(saveWidth);
   }
   if (Line.getWidth() > 1 || getStrokeWidth() > 1) updateFullWindow = true;
 }
Example #10
0
 void lineWidth() {
   int width = (int) IJ.getNumber("Line Width:", Line.getWidth());
   if (width == IJ.CANCELED) return;
   Line.setWidth(width);
   LineWidthAdjuster.update();
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp != null && imp.isProcessor()) {
     ImageProcessor ip = imp.getProcessor();
     ip.setLineWidth(Line.getWidth());
     Roi roi = imp.getRoi();
     if (roi != null && roi.isLine()) imp.draw();
   }
 }
 boolean setThresholdLevels(ImagePlus imp, ImageProcessor ip) {
   double t1 = ip.getMinThreshold();
   double t2 = ip.getMaxThreshold();
   boolean invertedLut = imp.isInvertedLut();
   boolean byteImage = ip instanceof ByteProcessor;
   if (ip instanceof ShortProcessor) imageType = SHORT;
   else if (ip instanceof FloatProcessor) imageType = FLOAT;
   else imageType = BYTE;
   if (t1 == ImageProcessor.NO_THRESHOLD) {
     ImageStatistics stats = imp.getStatistics();
     if (imageType != BYTE || (stats.histogram[0] + stats.histogram[255] != stats.pixelCount)) {
       IJ.error(
           "Particle Analyzer",
           "A thresholded image or 8-bit binary image is\n"
               + "required. Threshold levels can be set using\n"
               + "the Image->Adjust->Threshold tool.");
       canceled = true;
       return false;
     }
     boolean threshold255 = invertedLut;
     if (Prefs.blackBackground) threshold255 = !threshold255;
     if (threshold255) {
       level1 = 255;
       level2 = 255;
       fillColor = 64;
     } else {
       level1 = 0;
       level2 = 0;
       fillColor = 192;
     }
   } else {
     level1 = t1;
     level2 = t2;
     if (imageType == BYTE) {
       if (level1 > 0) fillColor = 0;
       else if (level2 < 255) fillColor = 255;
     } else if (imageType == SHORT) {
       if (level1 > 0) fillColor = 0;
       else if (level2 < 65535) fillColor = 65535;
     } else if (imageType == FLOAT) fillColor = -Float.MAX_VALUE;
     else return false;
   }
   imageType2 = imageType;
   if (redirectIP != null) {
     if (redirectIP instanceof ShortProcessor) imageType2 = SHORT;
     else if (redirectIP instanceof FloatProcessor) imageType2 = FLOAT;
     else if (redirectIP instanceof ColorProcessor) imageType2 = RGB;
     else imageType2 = BYTE;
   }
   return true;
 }
Example #12
0
  public void mousePressed(MouseEvent e) {
    // super.mousePressed(e);
    ImageProcessor ip = imp.getProcessor();
    ip.setLineWidth(1);
    if (Toolbar.getToolId() == Toolbar.DROPPER) IJ.setTool(Toolbar.RECTANGLE);

    Rectangle flipperRect = new Rectangle(86, 268, 18, 18);
    Rectangle resetRect = new Rectangle(86, 294, 18, 18);
    Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10);
    Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25);
    Rectangle background1Rect = new Rectangle(33, 302, 45, 10);
    Rectangle background2Rect = new Rectangle(56, 277, 23, 25);
    int x = offScreenX(e.getX());
    int y = offScreenY(e.getY());
    long difference = System.currentTimeMillis() - mouseDownTime;
    boolean doubleClick = (difference <= 250);
    mouseDownTime = System.currentTimeMillis();
    if (flipperRect.contains(x, y)) {
      Color c = Toolbar.getBackgroundColor();
      Toolbar.setBackgroundColor(Toolbar.getForegroundColor());
      Toolbar.setForegroundColor(c);
    } else if (resetRect.contains(x, y)) {
      Toolbar.setForegroundColor(new Color(0x000000));
      Toolbar.setBackgroundColor(new Color(0xffffff));
    } else if ((background1Rect.contains(x, y)) || (background2Rect.contains(x, y))) {
      background = true;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshForeground();
      ((ColorGenerator) ip).refreshBackground();
    } else if ((foreground1Rect.contains(x, y)) || (foreground2Rect.contains(x, y))) {
      background = false;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshBackground();
      ((ColorGenerator) ip).refreshForeground();
    } else {
      // IJ.log(" " + difference + " " + doubleClick);
      if (doubleClick) editColor();
      else {
        setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background);
      }
    }
    if (ip instanceof ColorGenerator) {
      if (background) {
        ((ColorGenerator) ip).refreshForeground();
        ((ColorGenerator) ip).refreshBackground();
      } else {
        ((ColorGenerator) ip).refreshBackground();
        ((ColorGenerator) ip).refreshForeground();
      }
    }
  }
 void drawOutline(ImageProcessor ip, Roi roi, int count) {
   if (showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS) {
     if (overlay == null) {
       overlay = new Overlay();
       overlay.drawLabels(true);
       overlay.setLabelFont(new Font("SansSerif", Font.PLAIN, fontSize));
     }
     Roi roi2 = (Roi) roi.clone();
     roi2.setStrokeColor(Color.cyan);
     if (lineWidth != 1) roi2.setStrokeWidth(lineWidth);
     if (showChoice == OVERLAY_MASKS) roi2.setFillColor(Color.cyan);
     overlay.add(roi2);
   } else {
     Rectangle r = roi.getBounds();
     int nPoints = ((PolygonRoi) roi).getNCoordinates();
     int[] xp = ((PolygonRoi) roi).getXCoordinates();
     int[] yp = ((PolygonRoi) roi).getYCoordinates();
     int x = r.x, y = r.y;
     if (!inSituShow) ip.setValue(0.0);
     ip.moveTo(x + xp[0], y + yp[0]);
     for (int i = 1; i < nPoints; i++) ip.lineTo(x + xp[i], y + yp[i]);
     ip.lineTo(x + xp[0], y + yp[0]);
     if (showChoice != BARE_OUTLINES) {
       String s = ResultsTable.d2s(count, 0);
       ip.moveTo(r.x + r.width / 2 - ip.getStringWidth(s) / 2, r.y + r.height / 2 + fontSize / 2);
       if (!inSituShow) ip.setValue(1.0);
       ip.drawString(s);
     }
   }
 }
Example #14
0
 void reset(ImagePlus imp, ImageProcessor ip) {
   // Assign the pixels of ip to the data in the restore array, while
   // taking care to not give the address the restore array to the
   // image processor.
   int[] pixels = (int[]) ip.getPixels();
   for (int i = 0; i < numPixels; i++) pixels[i] = restore[i];
 }
Example #15
0
  /*------------------------------------------------------------------*/
  void putColumn(ImageProcessor ip, int x, double[] column) {
    int width = ip.getWidth();

    if (ip.getHeight() != column.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < column.length); i++) {
        floatPixels[x] = (float) column[i];
        x += width;
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end putColumn */
Example #16
0
  /*------------------------------------------------------------------*/
  void putRow(ImageProcessor ip, int y, double[] row) {
    int rowLength = ip.getWidth();

    if (rowLength != row.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    y *= rowLength;
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < rowLength); i++) {
        floatPixels[y++] = (float) row[i];
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end putRow */
 /**
  * Returns an ImageProcessor for the specified slice, were 1<=n<=nslices. Returns null if the
  * stack is empty.
  */
 public ImageProcessor getProcessor(int n) {
   ImageProcessor ip;
   if (n < 1 || n > nSlices) throw new IllegalArgumentException(outOfRange + n);
   if (nSlices == 0) return null;
   if (stack[0] == null) throw new IllegalArgumentException("Pixel array is null");
   if (stack[0] instanceof byte[]) ip = new ByteProcessor(width, height, null, cm);
   else if (stack[0] instanceof short[]) ip = new ShortProcessor(width, height, null, cm);
   else if (stack[0] instanceof int[]) ip = new ColorProcessor(width, height, null);
   else if (stack[0] instanceof float[]) ip = new FloatProcessor(width, height, null, cm);
   else throw new IllegalArgumentException("Unknown stack type");
   ip.setPixels(stack[n - 1]);
   if (min != Double.MAX_VALUE && ip != null && !(ip instanceof ColorProcessor))
     ip.setMinAndMax(min, max);
   if (cTable != null) ip.setCalibrationTable(cTable);
   return ip;
 }
Example #18
0
 /** Opens a stack of images. */
 ImagePlus openStack(ColorModel cm, boolean show) {
   ImageStack stack = new ImageStack(fi.width, fi.height, cm);
   long skip = fi.getOffset();
   Object pixels;
   try {
     ImageReader reader = new ImageReader(fi);
     InputStream is = createInputStream(fi);
     if (is == null) return null;
     IJ.resetEscape();
     for (int i = 1; i <= fi.nImages; i++) {
       if (!silentMode) IJ.showStatus("Reading: " + i + "/" + fi.nImages);
       if (IJ.escapePressed()) {
         IJ.beep();
         IJ.showProgress(1.0);
         silentMode = false;
         return null;
       }
       pixels = reader.readPixels(is, skip);
       if (pixels == null) break;
       stack.addSlice(null, pixels);
       skip = fi.gapBetweenImages;
       if (!silentMode) IJ.showProgress(i, fi.nImages);
     }
     is.close();
   } catch (Exception e) {
     IJ.log("" + e);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory(fi.fileName);
     stack.trim();
   }
   if (!silentMode) IJ.showProgress(1.0);
   if (stack.getSize() == 0) return null;
   if (fi.sliceLabels != null && fi.sliceLabels.length <= stack.getSize()) {
     for (int i = 0; i < fi.sliceLabels.length; i++) stack.setSliceLabel(fi.sliceLabels[i], i + 1);
   }
   ImagePlus imp = new ImagePlus(fi.fileName, stack);
   if (fi.info != null) imp.setProperty("Info", fi.info);
   if (show) imp.show();
   imp.setFileInfo(fi);
   setCalibration(imp);
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMin() == ip.getMax()) // find stack min and max if first slice is blank
   setStackDisplayRange(imp);
   if (!silentMode) IJ.showProgress(1.0);
   silentMode = false;
   return imp;
 }
Example #19
0
    void setHistogram(ImagePlus imp, int j) {
      ImageProcessor ip = imp.getProcessor();
      ImageStatistics stats = ImageStatistics.getStatistics(ip, AREA + MODE, null);
      int maxCount2 = 0;
      histogram = stats.histogram;
      for (int i = 0; i < stats.nBins; i++)
        if ((histogram[i] > maxCount2) && (i != stats.mode)) maxCount2 = histogram[i];
      hmax = stats.maxCount;
      if ((hmax > (maxCount2 * 1.5)) && (maxCount2 != 0)) { // GL 1.5 was 2
        hmax = (int) (maxCount2 * 1.1); // GL 1.1 was 1.5
        histogram[stats.mode] = hmax;
      }
      os = null;
      ColorModel cm = ip.getColorModel();
      if (!(cm instanceof IndexColorModel)) return;
      IndexColorModel icm = (IndexColorModel) cm;
      int mapSize = icm.getMapSize();
      if (mapSize != 256) return;
      byte[] r = new byte[256];
      byte[] g = new byte[256];
      byte[] b = new byte[256];
      icm.getReds(r);
      icm.getGreens(g);
      icm.getBlues(b);
      hColors = new Color[256];

      if (isRGB) {
        if (j == 0) {
          for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, 0 & 255, 0 & 255);
        } else if (j == 1) {
          for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, i & 255, 0 & 255);
        } else if (j == 2) {
          for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, 0 & 255, i & 255);
        }
      } else {
        if (j == 0) {
          for (int i = 0; i < 256; i++) hColors[i] = new Color(r[i] & 255, g[i] & 255, b[i] & 255);
        } else if (j == 1) {
          for (int i = 0; i < 256; i++)
            // hColors[i] = new Color(127-i/2&255, 127+i/2&255, 127-i/2&255);
            hColors[i] = new Color(192 - i / 4 & 255, 192 + i / 4 & 255, 192 - i / 4 & 255);
        } else if (j == 2) {
          for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, i & 255, 0 & 255);
        }
      }
    }
Example #20
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() > 1) ip2.fillPolygon(roi.getPolygon());
   else roi.drawPixels(ip2);
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
Example #21
0
 void createMask(ImagePlus imp) {
   Roi roi = imp.getRoi();
   boolean useInvertingLut = Prefs.useInvertingLut;
   Prefs.useInvertingLut = false;
   if (roi == null || !(roi.isArea() || roi.getType() == Roi.POINT)) {
     createMaskFromThreshold(imp);
     Prefs.useInvertingLut = useInvertingLut;
     return;
   }
   ImagePlus maskImp = null;
   Frame frame = WindowManager.getFrame("Mask");
   if (frame != null && (frame instanceof ImageWindow))
     maskImp = ((ImageWindow) frame).getImagePlus();
   if (maskImp == null) {
     ImageProcessor ip = new ByteProcessor(imp.getWidth(), imp.getHeight());
     if (!Prefs.blackBackground) ip.invertLut();
     maskImp = new ImagePlus("Mask", ip);
     maskImp.show();
   }
   ImageProcessor ip = maskImp.getProcessor();
   ip.setRoi(roi);
   ip.setValue(255);
   ip.fill(ip.getMask());
   maskImp.updateAndDraw();
   Prefs.useInvertingLut = useInvertingLut;
 }
Example #22
0
  /*------------------------------------------------------------------*/
  public void getVerticalHessian(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[height];

    for (int x = 0; (x < width); x++) {
      getColumn(ip, x, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getHessian(line);
      putColumn(ip, x, line);
      stepProgressBar();
    }
  } /* end getVerticalHessian */
Example #23
0
  /*------------------------------------------------------------------*/
  public void getHorizontalGradient(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[width];

    for (int y = 0; (y < height); y++) {
      getRow(ip, y, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getGradient(line);
      putRow(ip, y, line);
      stepProgressBar();
    }
  } /* end getHorizontalGradient */
 private String addMean(int column, String line, int start) {
   if (start == -1) {
     line += "\tNaN";
     summaryHdr += "\t" + ResultsTable.getDefaultHeading(column);
   } else {
     float[] c = column >= 0 ? rt.getColumn(column) : null;
     if (c != null) {
       ImageProcessor ip = new FloatProcessor(c.length, 1, c, null);
       if (ip == null) return line;
       ip.setRoi(start, 0, ip.getWidth() - start, 1);
       ip = ip.crop();
       ImageStatistics stats = new FloatStatistics(ip);
       if (stats == null) return line;
       line += n(stats.mean);
     } else line += "\tNaN";
     summaryHdr += "\t" + rt.getColumnHeading(column);
   }
   return line;
 }
Example #25
0
 // get a pixel value; returns Float.NaN if outside the field.
 private float getPixel(int x, int y) {
   if (x < 0 || x >= width || y < 0 || y >= height) return Float.NaN;
   if (bpixels != null) return bpixels[y * width + x] & 0xff;
   else if (spixels != null) return spixels[y * width + x] & 0xffff;
   else if (fpixels != null) return fpixels[y * width + x];
   else if (exactPixelValue) // RGB for exact match
   return cpixels[y * width + x] & 0xffffff; // don't care for upper byte
   else // gray value of RGB
   return ip.getPixelValue(x, y);
 }
Example #26
0
 void createSelectionFromMask(ImagePlus imp) {
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMinThreshold() != ImageProcessor.NO_THRESHOLD) {
     IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", "");
     return;
   }
   if (!ip.isBinary()) {
     IJ.error(
         "Create Selection",
         "This command creates a composite selection from\n"
             + "a mask (8-bit binary image with white background)\n"
             + "or from an image that has been thresholded using\n"
             + "the Image>Adjust>Threshold tool. The current\n"
             + "image is not a mask and has not been thresholded.");
     return;
   }
   int threshold = ip.isInvertedLut() ? 255 : 0;
   ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE);
   IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", "");
 }
Example #27
0
 float[] getCurvature(float[] x, float[] y, int n) {
   float[] x2 = new float[n];
   float[] y2 = new float[n];
   for (int i = 0; i < n; i++) {
     x2[i] = x[i];
     y2[i] = y[i];
   }
   ImageProcessor ipx = new FloatProcessor(n, 1, x, null);
   ImageProcessor ipy = new FloatProcessor(n, 1, y, null);
   ipx.convolve(kernel, kernel.length, 1);
   ipy.convolve(kernel, kernel.length, 1);
   float[] indexes = new float[n];
   float[] curvature = new float[n];
   for (int i = 0; i < n; i++) {
     indexes[i] = i;
     curvature[i] =
         (float) Math.sqrt((x2[i] - x[i]) * (x2[i] - x[i]) + (y2[i] - y[i]) * (y2[i] - y[i]));
   }
   return curvature;
 }
Example #28
0
  void avg_col(ImageProcessor ip) {

    float sum; // sum of pixel values column
    float avg; // average pixel value of a column
    float[] sliceavgs = new float[width]; // means across columns of one slice
    int sliceNumber = ip.getSliceNumber() - 1; // slice number

    for (int x = 0; x < width; x += 1) {
      sum = 0; // reset with each column
      avg = 0; // reset with each column

      for (int y = 0; y < height; y += 1) {
        sum = sum + ip.getPixelValue(x, y);
      }
      avg = sum / height;
      sliceavgs[x] = avg; // building array of means
    }

    this.slicecols[sliceNumber] = sliceavgs; // add this slice's means to array
  }
Example #29
0
 ImagePlus duplicateStack(ImagePlus img1) {
   ImageStack stack1 = img1.getStack();
   int width = stack1.getWidth();
   int height = stack1.getHeight();
   int n = stack1.getSize();
   ImageStack stack2 = img1.createEmptyStack();
   try {
     for (int i = 1; i <= n; i++) {
       ImageProcessor ip1 = stack1.getProcessor(i);
       ip1.resetRoi();
       ImageProcessor ip2 = ip1.crop();
       stack2.addSlice(stack1.getSliceLabel(i), ip2);
     }
   } catch (OutOfMemoryError e) {
     stack2.trim();
     stack2 = null;
     return null;
   }
   return new ImagePlus("Duplicate", stack2);
 }
Example #30
0
 public void run(ImageProcessor ip) {
   int fg = Prefs.blackBackground ? 255 : 0;
   foreground = ip.isInvertedLut() ? 255 - fg : fg;
   background = 255 - foreground;
   ip.setSnapshotCopyMode(true);
   if (arg.equals("outline")) outline(ip);
   else if (arg.startsWith("fill")) fill(ip, foreground, background);
   else if (arg.startsWith("skel")) {
     ip.resetRoi();
     skeletonize(ip);
   } else if (arg.equals("erode") || arg.equals("dilate")) doIterations((ByteProcessor) ip, arg);
   else if (arg.equals("open")) {
     doIterations(ip, "erode");
     doIterations(ip, "dilate");
   } else if (arg.equals("close")) {
     doIterations(ip, "dilate");
     doIterations(ip, "erode");
   }
   ip.setSnapshotCopyMode(false);
   ip.setBinaryThreshold();
 }