Java Code Examples for ij.measure.ResultsTable#addValue()

The following examples show how to use ij.measure.ResultsTable#addValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ResultsTable measure(ResultsTable rt) {
	if (-1 == n_points) setupForDisplay(); //reload
	if (0 == n_points) return rt;
	if (null == rt) rt = Utils.createResultsTable("Pipe results", new String[]{"id", "length", "name-id"});
	// measure length
	double len = 0;
	final Calibration cal = layer_set.getCalibration();
	if (n_points > 1) {
		final VectorString3D vs = asVectorString3D();
		vs.calibrate(cal);
		len = vs.computeLength(); // no resampling
	}
	rt.incrementCounter();
	rt.addLabel("units", cal.getUnit());
	rt.addValue(0, this.id);
	rt.addValue(1, len);
	rt.addValue(2, getNameId());
	return rt;
}
 
Example 2
Source File: LabeledVoxelsMeasure.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get volume per labeled object based on the input
 * image calibration
 * 
 * @return volume per labeled object
 */
public ResultsTable getVolume()
{
	final int numLabels = objectVoxels.length;
	
	double volumePerVoxel = calibration.pixelWidth * calibration.pixelHeight * calibration.pixelDepth;
	
	// create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < numLabels; i++) 
	{
		table.incrementCounter();
		table.addLabel(Integer.toString( labels[i] ));
		table.addValue( "Volume", objectVoxels[ i ].size() * volumePerVoxel );
	}

	return table;
}
 
Example 3
Source File: MaxFeretDiameter3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts the result of maximum Feret diameters computation to a
 * ResultsTable that can be displayed within ImageJ.
 * 
 * @param maxDiamsMap
 *            the map of PointPair3D for each label within a label image
 * @return a ResultsTable instance
 */
public ResultsTable createTable(Map<Integer, PointPair3D> maxDiamsMap)
{
	// Create data table
	ResultsTable table = new ResultsTable();

	// compute ellipse parameters for each region
	for (int label : maxDiamsMap.keySet()) 
	{
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// add coordinates of origin pixel (IJ coordinate system)
		PointPair3D maxDiam = maxDiamsMap.get(label);
		table.addValue("Diameter", maxDiam.diameter());
		table.addValue("P1.x", maxDiam.p1.getX());
		table.addValue("P1.y", maxDiam.p1.getY());
		table.addValue("P1.z", maxDiam.p1.getZ());
		table.addValue("P2.x", maxDiam.p2.getX());
		table.addValue("p2.y", maxDiam.p2.getY());
		table.addValue("p2.z", maxDiam.p2.getZ());
	}
	
	// return the created array
	return table;
}
 
Example 4
Source File: GeometricMeasures2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Compute bounding box of each label in input stack and returns the result
 * as a ResultsTable.
 * 
 * @deprecated use BoundingBox class instead
 * 
 * @see inra.ijpb.measure.region2d.BoundingBox#analyzeRegions(ImageProcessor, int[], Calibration)
 * 
 * @param labelImage
 *            the input image containing label of particles
 * @return a data table containing for each labeled particle the extent in
 *         each dimension
 */
@Deprecated
public final static ResultsTable boundingBox(ImageProcessor labelImage) 
{
	int[] labels = LabelImages.findAllLabels(labelImage);
	int nbLabels = labels.length;

	double[][] boxes = boundingBox(labelImage, labels);

	// Create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < nbLabels; i++)
	{
		table.incrementCounter();
		table.addLabel(Integer.toString(labels[i]));
		table.addValue("XMin", boxes[i][0]);
		table.addValue("XMax", boxes[i][1]);
		table.addValue("YMin", boxes[i][2]);
		table.addValue("YMax", boxes[i][3]);
	}

	return table;
}
 
Example 5
Source File: AverageThickness.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ResultsTable createTable(Map<Integer, AverageThickness.Result> results)
{
    // Initialize a new result table
    ResultsTable table = new ResultsTable();

    // Convert all results that were computed during execution of the
    // "analyzeRegions()" method into rows of the results table
    for (int label : results.keySet())
    {
        // current diameter
        Result res = results.get(label);
        
        // add an entry to the resulting data table
        table.incrementCounter();
        table.addLabel(Integer.toString(label));
        table.addValue("AverageThickness", res.avgThickness);
    }

    return table;
}
 
Example 6
Source File: MaxFeretDiameter.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts the result of maximum Feret diameters computation to a
 * ResultsTable that can be displayed within ImageJ.
 * 
 * @param maxDiamsMap
 *            the map of PointPair2D for each label within a label image
 * @return a ResultsTable instance
 */
public ResultsTable createTable(Map<Integer, PointPair2D> maxDiamsMap)
{
	// Create data table
	ResultsTable table = new ResultsTable();

	// compute ellipse parameters for each region
	for (int label : maxDiamsMap.keySet()) 
	{
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// add coordinates of origin pixel (IJ coordinate system)
		PointPair2D maxDiam = maxDiamsMap.get(label);
		table.addValue("Diameter", maxDiam.diameter());
		table.addValue("Orientation", Math.toDegrees(maxDiam.angle()));
		table.addValue("P1.x", maxDiam.p1.getX());
		table.addValue("P1.y", maxDiam.p1.getY());
		table.addValue("P2.x", maxDiam.p2.getX());
		table.addValue("p2.y", maxDiam.p2.getY());
	}
	
	// return the created array
	return table;
}
 
Example 7
Source File: Profile.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Measures the calibrated length, the lateral surface as the length times the layer thickness, and the volume (if closed) as the area times the layer thickness. */
@Override
public ResultsTable measure(ResultsTable rt) {
	if (null == rt) rt = Utils.createResultsTable("Profile results", new String[]{"id", "length", "side surface: length x thickness", "volume: area x thickness", "name-id"});
	if (-1 == n_points) setupForDisplay();
	if (n_points < 2) return null;
	if (0 == p_i[0].length) generateInterpolatedPoints(0.05);
	final Calibration cal = getLayerSet().getCalibration();
	// computeLength returns a calibrated length, so only calibrate the layer thickness:
	final double len = computeLength();
	final double surface_flat = len * layer.getThickness() * cal.pixelWidth;
	rt.incrementCounter();
	rt.addLabel("units", cal.getUnit());
	rt.addValue(0, id);
	rt.addValue(1, len);
	rt.addValue(2, surface_flat);
	final double volume = closed ? computeArea() * layer.getThickness() * cal.pixelWidth : 0;
	rt.addValue(3, volume);
	rt.addValue(4, getNameId());
	return rt;
}
 
Example 8
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the volume similarity between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * Volume Similarity (for each label region r) $VS_r = 2\frac{ |S_r| - |T_r| }{ |S_r| + |T_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return volume similarity per label
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getVolumeSimilarityPerLabel(
		ImageStack sourceImage,
		ImageStack targetImage )
{
	int[] sourceLabels = findAllLabels( sourceImage );
	int[] numPixSource = voxelCount( sourceImage, sourceLabels );
	double[] volumeSim = new double[ sourceLabels.length ];

    int[] targetLabels = findAllLabels( targetImage );
	int[] numPixTarget = voxelCount( targetImage, targetLabels );

	// create associative array to identify the index of each label
    HashMap<Integer, Integer> targetLabelIndices = mapLabelIndices( targetLabels );

    // calculate the volume similarity of the source labels
    for( int i = 0; i < sourceLabels.length; i ++ )
    	volumeSim[ i ] = targetLabelIndices.get( sourceLabels[ i ] ) != null ?
    			2.0 * ( numPixSource[ i ] - numPixTarget[ targetLabelIndices.get( sourceLabels[ i ] ) ] )
    			/ ( numPixSource[ i ] + numPixTarget[ targetLabelIndices.get( sourceLabels[ i ] ) ] )
    			: 0;
	// create data table
 		ResultsTable table = new ResultsTable();
 		for (int i = 0; i < sourceLabels.length; i++) {
 			table.incrementCounter();
 			table.addLabel(Integer.toString( sourceLabels[ i ] ));
 			table.addValue("VolumeSimilarity", volumeSim[ i ] );
 		}
 	    return table;
}
 
Example 9
Source File: EquivalentEllipsoid.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Utility method that transforms the mapping between labels and equivalent
 * ellipsoids instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Equivalent Ellipsoids
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Ellipsoid> map)
{
	// Initialize a new result table
	ResultsTable table = new ResultsTable();

	// Convert all results that were computed during execution of the
	// "computeGeodesicDistanceMap()" method into rows of the results table
	for (int label : map.keySet())
	{
		// current diameter
		Ellipsoid ellipse = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of centroid
		Point3D center = ellipse.center();
		table.addValue("Ellipsoid.Center.X", center.getX());
		table.addValue("Ellipsoid.Center.Y", center.getY());
		table.addValue("Ellipsoid.Center.Z", center.getZ());
		
		// ellipse size
		table.addValue("Ellipsoid.Radius1", ellipse.radius1());
		table.addValue("Ellipsoid.Radius2", ellipse.radius2());
		table.addValue("Ellipsoid.Radius3", ellipse.radius3());

		// ellipse orientation (in degrees)
		table.addValue("Ellipsoid.Phi", ellipse.phi());
		table.addValue("Ellipsoid.Theta", ellipse.theta());
		table.addValue("Ellipsoid.Psi", ellipse.psi());
	}

	return table;
}
 
Example 10
Source File: GeometricMeasures3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Measures the volume of each particle in a 3D label image.
 * 
 * @deprecated used IntrinsicVolumes3D instead
 * 
 * @param labelImage image containing the label of each particle
 * @param resol image resolution, as a double array with 3 elements
 * @return the volume of each particle in the image
 */
@Deprecated
public final static ResultsTable volume(ImageStack labelImage, double[] resol) 
{
	Calibration calib = new Calibration();
	calib.pixelWidth = resol[0];
	calib.pixelHeight = resol[1];
	calib.pixelDepth = resol[2];
	
	IJ.showStatus("Compute volume...");
	int[] labels = LabelImages.findAllLabels(labelImage);
	int nbLabels = labels.length;

	double[] volumes = IntrinsicVolumes3D.volumes(labelImage, labels, calib);

	// Create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < nbLabels; i++) 
	{
		table.incrementCounter();
		table.addLabel(Integer.toString(labels[i]));
		table.addValue("Volume", volumes[i]);
	}

	IJ.showStatus("");
	return table;
}
 
Example 11
Source File: InertiaEllipsoidPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ResultsTable createVectorTable(int[] labels, InertiaMoments3D[] moments)
  {
// Initialize a new result table
ResultsTable table = new ResultsTable();
	
for (int i = 0; i < labels.length; i++)
{
	// add an entry to the resulting data table
	table.incrementCounter();
	table.addLabel(Integer.toString(labels[i]));

	ArrayList<Vector3D> vectors = moments[i].eigenVectors();
	
	Vector3D v1 = vectors.get(0);
	table.addValue("EigenVector1.X", v1.getX());
	table.addValue("EigenVector1.Y", v1.getY());
	table.addValue("EigenVector1.Z", v1.getZ());
	
	Vector3D v2 = vectors.get(1);
	table.addValue("EigenVector2.X", v2.getX());
	table.addValue("EigenVector2.Y", v2.getY());
	table.addValue("EigenVector2.Z", v2.getZ());
	
	Vector3D v3 = vectors.get(2);
	table.addValue("EigenVector3.X", v3.getX());
	table.addValue("EigenVector3.Y", v3.getY());
	table.addValue("EigenVector3.Z", v3.getZ());

}

  	return table;
  }
 
Example 12
Source File: InertiaEllipse.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Utility method that transforms the mapping between labels and inertia
 * ellipses instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Inertia Ellipses
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Ellipse> map)
{
	// Initialize a new result table
	ResultsTable table = new ResultsTable();

	// Convert all results that were computed during execution of the
	// "computeGeodesicDistanceMap()" method into rows of the results table
	for (int label : map.keySet())
	{
		// current diameter
		Ellipse ellipse = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of centroid
		Point2D center = ellipse.center();
		table.addValue("Ellipse.Center.X", center.getX());
		table.addValue("Ellipse.Center.Y", center.getY());
		
		// ellipse size
		table.addValue("Ellipse.Radius1", ellipse.radius1());
		table.addValue("Ellipse.Radius2", ellipse.radius2());

		// ellipse orientation (degrees)
		table.addValue("Ellipse.Orientation", ellipse.orientation());
	}

	return table;
}
 
Example 13
Source File: EquivalentEllipse.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Utility method that transforms the mapping between labels and equivalent
 * ellipses instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Inertia Ellipses
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Ellipse> map)
{
	// Initialize a new result table
	ResultsTable table = new ResultsTable();

	// Convert all results that were computed into rows of the results table
	for (int label : map.keySet())
	{
		// current diameter
		Ellipse ellipse = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of centroid
		Point2D center = ellipse.center();
		table.addValue("Ellipse.Center.X", center.getX());
		table.addValue("Ellipse.Center.Y", center.getY());
		
		// ellipse size
		table.addValue("Ellipse.Radius1", ellipse.radius1());
		table.addValue("Ellipse.Radius2", ellipse.radius2());

		// ellipse orientation (degrees)
		table.addValue("Ellipse.Orientation", ellipse.orientation());
	}

	return table;
}
 
Example 14
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get maximum voxel values per label
 * 
 * @return result table with maximum values per label
 */
public ResultsTable getMax()
{
	this.max = maxPerLabel();
	
	// create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < objectVoxels.length; i++) {
		table.incrementCounter();
		table.addLabel(Integer.toString( labels[i] ));
		table.addValue("Max", max[i]);
	}

	return table;
}
 
Example 15
Source File: GeometricMeasures2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes perimeter of each label using Crofton method.
 * 
 * @deprecated use analyzeRegions instead
 * @see #analyzeRegions(ij.process.ImageProcessor, double[])
 * 
 * @param labelImage
 *            the input image containing label of particles
 * @param nDirs
 *            the number of directions to process, either 2 or 4
 * @param resol
 *            the spatial resolution
 * @return a data table containing the perimeter of each labeled particle
 */
@Deprecated
public static final ResultsTable croftonPerimeter(
		ImageProcessor labelImage, double[] resol, int nDirs)
{
	// Check validity of parameters
	if (labelImage == null)
		return null;

	int[] labels = LabelImages.findAllLabels(labelImage);
	int nbLabels = labels.length;

	Calibration calib = new Calibration();
	calib.pixelWidth = resol[0];
	calib.pixelHeight = resol[1];
	double[] areas = IntrinsicVolumes2D.areas(labelImage, labels, calib);
	double[] perims = IntrinsicVolumes2D.perimeters(labelImage, labels, calib, nDirs);

	// Create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < nbLabels; i++) 
	{
		int label = labels[i];

		table.incrementCounter();
		table.addLabel(Integer.toString(label));

		table.addValue("Area", areas[i]);
		table.addValue("Perimeter", perims[i]);

		// Also compute circularity (ensure value is between 0 and 1)
		double p = perims[i];
		double circu = Math.min(4 * Math.PI * areas[i] / (p * p), 1);
		table.addValue("Circularity", circu);
		table.addValue("Elong.", 1. / circu);
	}
	IJ.showStatus("");

	return table;
}
 
Example 16
Source File: Lines_.java    From ij-ridgedetection with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the results table.
 *
 * @param showJunctions
 *            the show junctions
 */
private void createResultsTable(boolean showJunctions) {
	ResultsTable rt = ResultsTable.getResultsTable();
	ResultsTable rtSum = new ResultsTable();
	rt.setPrecision(3);

	Calibration cal = imp.getCalibration();
	for (Lines contours : result) {
		for (Line c : contours) {
			double meanWidth = 0;
			for (int i = 0; i < c.num; i++) {
				rt.incrementCounter();
				rt.addValue("Frame", contours.getFrame());

				rt.addValue("Contour ID", c.getID());
				rt.addValue("Pos.", i + 1);
				rt.addValue("X", c.col[i] * cal.pixelWidth);

				rt.addValue("Y", c.row[i] * cal.pixelHeight);
				rt.addValue("Length", c.estimateLength() * cal.pixelHeight);
				if (doCorrectPosition && doEstimateWidth) {
					rt.addValue("Contrast", Math.abs(c.intensity[i]));
					rt.addValue("Asymmetry", Math.abs(c.asymmetry[i]));
				}
				if (doEstimateWidth) {

					rt.addValue("Line width", (c.width_l[i] + c.width_r[i]) * cal.pixelWidth);
					meanWidth += c.width_l[i] + c.width_r[i];
					rt.addValue("Angle of normal", c.angle[i]);
				}
				rt.addValue("Class", c.getContourClass().toString().substring(5));
			}
			rtSum.incrementCounter();
			rtSum.addValue("Frame", contours.getFrame());
			rtSum.addValue("Contour ID", c.getID());
			rtSum.addValue("Length", c.estimateLength() * cal.pixelWidth);

			if (doEstimateWidth) {
				rtSum.addValue("Mean line width", meanWidth / c.num * cal.pixelWidth);
			}
		}
	}

	rt.show("Results");
	rtSum.show("Summary");

	if (showJunctions) {
		ResultsTable rt2 = new ResultsTable();
		rt2.setPrecision(0);
		for (Junctions junctions : resultJunction) {
			for (Junction j : junctions) {
				rt2.incrementCounter();
				rt2.addValue("Frame", junctions.getFrame());
				rt2.addValue("Contour ID 1", j.getLine1().getID());// c.get( j.cont1)
				rt2.addValue("Contour ID 2", j.getLine2().getID());
				rt2.addValue("X", j.x * cal.pixelWidth);
				rt2.addValue("Y", j.y * cal.pixelHeight);
			}
		}
		rt2.show("Junctions");
	}
}
 
Example 17
Source File: GeometricMeasures2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Computes perimeter density of the binary image using Crofton method with
 * 4 directions (orthogonal and diagonal).
 * 
 * @param image
 *            the input binary image
 * @param resol
 *            the spatial resolution
 * @return an array containing for each label, an estimate of the region perimeter
 */
private static final ResultsTable perimeterDensity_D4(ImageProcessor image,
		double[] resol) 
{
	// Create data table
	ResultsTable table = new ResultsTable();
	double perim;

	double d1 = resol[0];
	double d2 = resol[1];
	double d12 = Math.hypot(d1, d2);

	// area of a pixel (used for computing line densities)
	double pixelArea = d1 * d2;

	// compute weights associated to each direction
	double[] weights = computeDirectionWeightsD4(resol);

	double area = particleArea(image, 255) * pixelArea;

	// Count number of transitions in each direction
	int n1 = countTransitionsD00(image, 255, false);
	int n2 = countTransitionsD90(image, 255, false);
	int n3 = countTransitionsD45(image, 255, false);
	int n4 = countTransitionsD135(image, 255, false);

	// Compute weighted diameters and multiplies by associated
	// direction weights
	double wd1 = (n1 / d1) * weights[0];
	double wd2 = (n2 / d2) * weights[1];
	double wd3 = (n3 / d12) * weights[2];
	double wd4 = (n4 / d12) * weights[3];

	// Compute perimeter
	perim = (wd1 + wd2 + wd3 + wd4) * pixelArea * Math.PI / 2;

	// Add new row in table
	table.incrementCounter();

	// area
	table.addValue("Area", area);

	// Compute porosity by dividing by observed area
	int pixelCount = image.getWidth() * image.getHeight();
	double refArea = pixelCount * pixelArea;
	table.addValue("A. Density", area / refArea);

	if (debug) 
	{
		// Display individual counts
		table.addValue("N1", n1);
		table.addValue("N2", n2);
		table.addValue("N3", n3);
		table.addValue("N4", n4);
	}

	// Display perimeter value
	table.addValue("Perimeter", perim);

	// compute perimeter density
	double refArea2 = (image.getWidth() - 1) * (image.getHeight() - 1)
			* pixelArea;
	double perimDensity = perim / refArea2;
	table.addValue("P. Density", perimDensity);

	return table;
}
 
Example 18
Source File: GeometricMeasures2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
	 * Computes several morphometric features for each region in the input label
	 * image and specifying number of directions to use for measuring perimeter.
	 * 
	 * @param labelImage
	 *            the input image containing label of particles
	 * @param resol
	 *            the spatial resolution
	 * @param nDirs
	 *            the number of directions for perimeter measure
	 * @return a data table containing the area, the perimeter and the
	 *         "circularity" of each labeled particle
	 */
	@Deprecated
	public static final ResultsTable analyzeRegions(ImageProcessor labelImage,
			double[] resol, int nDirs)
	{
		// Check validity of parameters
		if (labelImage == null)
			return null;

		// identify the labels
		int[] labels = LabelImages.findAllLabels(labelImage);
		int nbLabels = labels.length;

		// compute area and perimeter (use 4 directions by default)
//		double[] areas = area(labelImage, labels, resol);
//		double[] perims = croftonPerimeter(labelImage, labels, resol, nDirs);
		Calibration calib = new Calibration();
		calib.pixelWidth = resol[0];
		calib.pixelHeight = resol[1];
		double[] areas = IntrinsicVolumes2D.areas(labelImage, labels, calib);
		double[] perims = IntrinsicVolumes2D.perimeters(labelImage, labels, calib, nDirs);

		// Create data table, and add shape parameters
		ResultsTable table = new ResultsTable();
		for (int i = 0; i < nbLabels; i++)
		{
			int label = labels[i];

			table.incrementCounter();
			table.addLabel(Integer.toString(label));

			table.addValue("Area", areas[i]);
			table.addValue("Perimeter", perims[i]);

			// Also compute circularity (ensure value is between 0 and 1)
			double p = perims[i];
			double circu = Math.min(4 * Math.PI * areas[i] / (p * p), 1);
			table.addValue("Circularity", circu);
			table.addValue("Elong.", 1. / circu);
		}
		IJ.showStatus("");

		return table;
	}
 
Example 19
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get kurtosis voxel values per label
 *
 * @return result table with kurtosis values per label
 */
public ResultsTable getKurtosis()
{
	final int numLabels = objectVoxels.length;
	// check if the mean intensity per label has already
	// been calculated
	if( null == this.mean )
		this.mean = meanPerLabel();

	double[] kurtosis = new double[ numLabels ];

	// calculate kurtosis voxel value per object
	for( int i=0; i<numLabels; i++ )
	{
		final double voxelCount = objectVoxels[ i ].size();
		double v, v2, sum2 = 0, sum3 = 0, sum4 = 0;
		for( int j=0; j<voxelCount; j++ )
		{
			v = objectVoxels[ i ].get( j ) + Double.MIN_VALUE;
			v2 = v * v;
			sum2 += v2;
			sum3 += v * v2;
			sum4 += v2 * v2;
		}

		double mean2 = mean[ i ] * mean[ i ];
		double variance = sum2 / voxelCount - mean2;
		kurtosis[ i ] = Double.compare( variance, 0d ) == 0 ? -6.0/5.0 :
			(((sum4 - 4.0 * mean[ i ] * sum3 + 6.0 * mean2 * sum2 )
				/ voxelCount - 3.0 * mean2 * mean2 )
				/ ( variance * variance ) -3.0 );
	}

	// create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < numLabels; i++) {
		table.incrementCounter();
		table.addLabel( Integer.toString( labels[ i ] ) );
		table.addValue( "Kurtosis", kurtosis[ i ] );
	}

	return table;
}
 
Example 20
Source File: MicrostructureAnalysisPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* Main body of the plugin. Computes geometric measures on the image
* contained in <code>image</code>, using <code>nDirs</code> discrete
* directions. If the addPorosity flag is set to true, an additional column
* equal to 1-area density is added.
* 
* @param image
*            the image to process
* @param nDirs
*            the number of directions to consider, either 2 or 4
* @param addPorosity
 *            specifies if porosity should be computed
* @return an array of objects
* @deprecated use process method instead
*/
  @Deprecated
  public Object[] exec(ImagePlus image, int nDirs, boolean addPorosity) {
      // Check validity of parameters
      if (image==null) 
          return null;

      if (debug) {
      	System.out.println("Compute Crofton densities on image '" 
      			+ image.getTitle() + "' using " + nDirs 
      			+ " directions.");
      }
      
      ImageProcessor proc = image.getProcessor();
      
      // Extract spatial calibration
      Calibration calib = image.getCalibration();
      
      // Compute basis measures
      double areaDensity =  IntrinsicVolumes2D.areaDensity(proc);
      double perimDensity = IntrinsicVolumes2D.perimeterDensity(proc, calib, nDirs);
      ResultsTable table = new ResultsTable();
      table.incrementCounter();
      table.addValue("AreaDensity", areaDensity);
      table.addValue("PerimeterDensity", perimDensity);
      
      // eventually add the porosity for those who do not want to subtract by hand...
      if (addPorosity)
      {
     	 table.addValue("Porosity", 1-areaDensity);
      }

// create string for indexing results
String tableName = removeImageExtension(image.getTitle()) + "-Densities"; 
  
// show result
table.show(tableName);

// return the created array
return new Object[]{"Crofton Densties", table};
  }