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

The following examples show how to use ij.measure.ResultsTable#addLabel() . 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: Centroid3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Utility method that transforms the mapping between labels and Point3D
 * instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Point3Ds
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Point3D> 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
		Point3D point = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of centroid
		table.addValue("Centroid.X", point.getX());
		table.addValue("Centroid.Y", point.getY());
		table.addValue("Centroid.Z", point.getZ());
	}

	return table;
}
 
Example 2
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get the false negative error between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * False Negative Error (for each individual labeled region r) $FN_r = \frac{ |T_r \setminus S_r| }{ |T_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return false negative error per label or null if error
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getFalseNegativeErrorPerLabel(
		ImageProcessor sourceImage,
		ImageProcessor targetImage )
{
	if( sourceImage.getWidth() != targetImage.getWidth() ||
			sourceImage.getHeight() != targetImage.getHeight() )
		return null;

	ResultsTable toTable = LabelImages.getTargetOverlapPerLabel( sourceImage, targetImage );
	// create data table
 		ResultsTable fneTable = new ResultsTable();
 		for (int i = 0; i < toTable.getCounter(); i++) {
 			fneTable.incrementCounter();
 			fneTable.addLabel( toTable.getLabel( i ) );
 			fneTable.addValue( "FalseNegativeError", 1.0 - toTable.getValue("TargetOverlap", i) );
 		}
 	    return fneTable;
}
 
Example 3
Source File: Polyline.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("Polyline 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 4
Source File: Convexity.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ResultsTable createTable(Map<Integer, Convexity.Result> results)
{
	// 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 : 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("Area", res.area);
		table.addValue("ConvexArea", res.convexArea);
		table.addValue("Convexity", res.convexity);
	}

	return table;
}
 
Example 5
Source File: Dissector.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
final void addResults(final ResultsTable rt, final Calibration cal, final double nameid) {
	for (int i=0; i<n_points; i++) {
		final Layer la = layer_set.getLayer(p_layer[i]);
		if (null == layer) {
			Utils.log("Dissector.addResults: could not find layer with id " + p_layer[i]);
			continue;
		}
		final Point2D.Double po = M.transform(Dissector.this.at, p[0][i], p[1][i]);
		rt.incrementCounter();
		rt.addLabel("units", cal.getUnit());
		rt.addValue(0, Dissector.this.id);
		rt.addValue(1, tag);
		rt.addValue(2, po.x * cal.pixelWidth);
		rt.addValue(3, po.y * cal.pixelHeight);
		rt.addValue(4, la.getZ() * cal.pixelWidth); // layer Z is in pixels
		rt.addValue(5, radius * cal.pixelWidth);
		rt.addValue(6, nameid);
	}
}
 
Example 6
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get median voxel values per label
 *
 * @return result table with median values per label
 */
public ResultsTable getMedian()
{
	final int numLabels = objectVoxels.length;

	double[] median = new double[ numLabels ];

	// calculate median voxel value per object
	for( int i=0; i<numLabels; i++ )
	{
		Collections.sort( objectVoxels[ i ] );
		median[ i ] = objectVoxels[ i ].get( objectVoxels[ i ].size() / 2 );
	}

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

	return table;
}
 
Example 7
Source File: BoundingBox.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Utility method that transforms the mapping between labels and bounding
 * boxes instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and bounding Boxes
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Box2D> 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
		Box2D box = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of centroid
		table.addValue("Box2D.XMin", box.getXMin());
		table.addValue("Box2D.XMax", box.getXMax());
		table.addValue("Box2D.YMin", box.getYMin());
		table.addValue("Box2D.YMax", box.getYMax());
	}

	return table;
}
 
Example 8
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the standard deviation of the intensity values of the neighbor labels
 *
 * @return result table with standard deviation values of neighbor labels
 */
public ResultsTable getNeighborsStdDev()
{
	// Check if neighbors mean already exists
	if( null == neighborsMean )
		this.neighborsMean = neighborsMeanPerLabel();
	// Check if neighbor voxels have been calculated
	if( this.neighborVoxels == null )
		this.neighborVoxels = computeNeighborVoxels();
	final int numLabels = neighborsMean.length;

	double[] sd = new double[ numLabels ];

	// Calculate standard deviation
	for( int i=0; i<numLabels; i++ )
	{
		if( neighborVoxels[ i ].size() > 0 )
		{
			for( final double v : neighborVoxels[ i ] )
			{
				double diff = v - neighborsMean[ i ];
				sd[ i ] += diff * diff;
			}
			sd[ i ] /= neighborVoxels[ i ].size();
			sd[ i ] = Math.sqrt( sd[ i ] );
		}
		else
			sd[ i ] = Double.NaN;
	}

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

	return table;
}
 
Example 9
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the false negative error between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * False Negative Error (for each individual labeled region r) $FN_r = \frac{ |T_r \setminus S_r| }{ |T_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return false negative error per label or null if error
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getFalseNegativeErrorPerLabel(
		ImageStack sourceImage,
		ImageStack targetImage )
{
	ResultsTable toTable = LabelImages.getTargetOverlapPerLabel( sourceImage, targetImage );
	// create data table
 		ResultsTable fneTable = new ResultsTable();
 		for (int i = 0; i < toTable.getCounter(); i++) {
 			fneTable.incrementCounter();
 			fneTable.addLabel( toTable.getLabel( i ) );
 			fneTable.addValue( "FalseNegativeError", 1.0 - toTable.getValue("TargetOverlap", i) );
 		}
 	    return fneTable;
}
 
Example 10
Source File: InertiaEllipsoid.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
 * ellipsoids instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Inertia 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 11
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the false positive error between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * False Positive Error (for each individual labeled region r) $FN_r = \frac{ |S_r \setminus T_r| }{ |S_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return false positive error per label or null if error
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getFalsePositiveErrorPerLabel(
		ImageProcessor sourceImage,
		ImageProcessor targetImage )
{
	if( sourceImage.getWidth() != targetImage.getWidth() ||
			sourceImage.getHeight() != targetImage.getHeight() )
		return null;

	int[] sourceLabels = findAllLabels( sourceImage );
	double[] setDiff = new double[ sourceLabels.length ];
	// create associative array to identify the index of each label
    HashMap<Integer, Integer> sourceLabelIndices = mapLabelIndices( sourceLabels );
    int[] numPixSource = pixelCount( sourceImage, sourceLabels );

	// calculate the set difference between source and target
    for( int i = 0; i < sourceImage.getWidth(); i++ )
    	for( int j = 0; j < sourceImage.getHeight(); j++ )
    		if( sourceImage.getf( i, j ) > 0 ) // skip label 0 (background)
    		{
    			if( sourceImage.getf( i, j ) != targetImage.getf( i, j ) )
    				setDiff[ sourceLabelIndices.get( (int) sourceImage.getf( i, j ) ) ] ++;
    		}
    // return the false positive error
    for( int i = 0; i < setDiff.length; i ++ )
    	setDiff[ i ] /= numPixSource[ i ];

    // 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( "FalsePositiveError", setDiff[ i ] );
 		}
 	    return table;
}
 
Example 12
Source File: LargestInscribedCircle.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 inscribed
 * circle instances into a ResultsTable that can be displayed with ImageJ.
 * 
 * @param map
 *            the mapping between labels and Circle2D instances
 * @return a ResultsTable that can be displayed with ImageJ.
 */
public ResultsTable createTable(Map<Integer, Circle2D> 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
		Circle2D circle = map.get(label);
		
		// add an entry to the resulting data table
		table.incrementCounter();
		table.addLabel(Integer.toString(label));
		
		// coordinates of circle center
		table.addValue("InscrCircle.Center.X", circle.getCenter().getX());
		table.addValue("InscrCircle.Center.Y", circle.getCenter().getY());
		
		// circle radius
		table.addValue("InscrCircle.Radius", circle.getRadius());
	}

	return table;
}
 
Example 13
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the mean intensity values of the neighbor labels
 *
 * @return result table with mean values of neighbor labels
 */
public ResultsTable getNeighborsMean()
{
	this.neighborsMean = neighborsMeanPerLabel();

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

	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 standard deviation of voxel values per label
 * 
 * @return result table with standard deviation values per label
 */
public ResultsTable getStdDev()
{
	final int numLabels = objectVoxels.length;
	
	// check if the mean intensity per label has already
	// been calculated
	if( null == this.mean )
		this.mean = meanPerLabel();
	double[] sd = new double[ numLabels ];

	// calculate standard deviation
	for( int i=0; i<numLabels; i++ )
	{
		sd[ i ] = 0;
		double diff;
		for( final double v : objectVoxels[ i ] )
		{
			diff = v - mean[ i ];
			sd[ i ] += diff * diff;
		}
		sd[ i ] /= objectVoxels[ i ].size();
		sd[ i ] = Math.sqrt( sd[ i ] );
	}
	
	// create data table
	ResultsTable table = new ResultsTable();
	for (int i = 0; i < numLabels; i++) {
		table.incrementCounter();
		table.addLabel(Integer.toString( labels[i] ));
		table.addValue("StdDev", sd[i]);
	}

	return table;
}
 
Example 15
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 16
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the target overlap between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * Target Overlap (for individual label regions r) $TO_r = \frac{ |S_r \cap T_r| }{ |T_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return target overlap per label or null if error
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getTargetOverlapPerLabel(
		ImageStack sourceImage,
		ImageStack targetImage )
{
	if( sourceImage.getWidth() != targetImage.getWidth() ||
			sourceImage.getHeight() != targetImage.getHeight() )
		return null;

	int[] sourceLabels = findAllLabels( sourceImage );
	double[] intersection = new double[ sourceLabels.length ];
	// create associative array to identify the index of each label
    HashMap<Integer, Integer> sourceLabelIndices = mapLabelIndices( sourceLabels );

    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 pixel to pixel intersection
 	for( int k = 0; k < sourceImage.getSize(); k ++ )
 	{
 		final ImageProcessor ls = sourceImage.getProcessor( k+1 );
		final ImageProcessor lt = targetImage.getProcessor( k+1 );
 		for( int i = 0; i < sourceImage.getWidth(); i++ )
 			for( int j = 0; j < sourceImage.getHeight(); j++ )
 				if( ls.getf( i, j ) > 0 ) // skip label 0 (background)
 				{
 					if( ls.getf( i, j ) == lt.getf( i, j ) )
 						intersection[ sourceLabelIndices.get( (int) ls.getf( i, j ) ) ] ++;
 				}
 	}
    // return the target overlap
    for( int i = 0; i < intersection.length; i ++ )
    	intersection[ i ] = targetLabelIndices.get( sourceLabels[ i ] ) != null ?
    			intersection[ 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("TargetOverlap", intersection[i]);
	}
    return table;
}
 
Example 17
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the Dice coefficient per label (intersection over union overlap) between
 * two label images.
 * @param labelImage1 reference label image
 * @param labelImage2 label image to compare with
 * @return Dice coefficient per label in the reference image or null if error
 * @see <a href="https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient">https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient</a>
 */
public static final ResultsTable getDiceCoefficientPerLabel(
		ImageStack labelImage1,
		ImageStack labelImage2 )
{
	if( labelImage1.getWidth() != labelImage2.getWidth() ||
			labelImage1.getHeight() != labelImage2.getHeight() )
		return null;

	int[] labels1 = findAllLabels( labelImage1 );
	int[] numPix1 = voxelCount( labelImage1, labels1 );
	double[] intersection = new double[ labels1.length ];
	// create associative array to identify the index of each label
    HashMap<Integer, Integer> labelIndices1 = mapLabelIndices( labels1 );

    int[] labels2 = findAllLabels( labelImage2 );
	int[] numPix2 = voxelCount( labelImage2, labels2 );

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

	// calculate the voxel to voxel intersection
    for( int k = 0; k < labelImage1.getSize(); k ++ )
	{
		final ImageProcessor l1 = labelImage1.getProcessor( k+1 );
		final ImageProcessor l2 = labelImage2.getProcessor( k+1 );
		for( int i = 0; i < labelImage1.getWidth(); i++ )
			for( int j = 0; j < labelImage1.getHeight(); j++ )
				if( l1.getf( i, j ) > 0 ) // skip label 0 (background)
	    		{
					if( l1.getf( i, j ) == l2.getf( i, j ) )
						intersection[ labelIndices1.get( (int) l1.getf( i, j ) ) ] ++;
	    		}
	}
    // return the Dice coefficient
    for( int i = 0; i < intersection.length; i ++ )
    {
    	int num2 = labelIndices2.get( labels1[ i ] ) != null ? numPix2[ labelIndices2.get( labels1[ i ] ) ] : 0;
    	intersection[ i ] = 2.0 * intersection[ i ]  / ( numPix1[ i ] + num2 );
    }
    // create data table
 		ResultsTable table = new ResultsTable();
 		for (int i = 0; i < labels1.length; i++) {
 			table.incrementCounter();
 			table.addLabel(Integer.toString( labels1[i] ));
 			table.addValue("DiceCoefficient", intersection[i]);
 		}
 	    return table;
}
 
Example 18
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get skewness voxel values per label
 *
 * @return result table with skewness values per label
 */
public ResultsTable getSkewness()
{
	final int numLabels = objectVoxels.length;
	// check if the mean intensity per label has already
	// been calculated
	if( null == this.mean )
		this.mean = meanPerLabel();

	double[] skewness = new double[ numLabels ];

	// calculate skewness voxel value per object
	for( int i=0; i<numLabels; i++ )
	{
		final double voxelCount = objectVoxels[ i ].size();
		double v, v2, sum2 = 0, sum3 = 0;
		for( int j=0; j<voxelCount; j++ )
		{
			v = objectVoxels[ i ].get( j ) + Double.MIN_VALUE;
			v2 = v * v;
			sum2 += v2;
			sum3 += v * v2;
		}
		double mean2 = mean[ i ] * mean[ i ];
		double variance = sum2 / voxelCount - mean2;
		double sDeviation = Math.sqrt( variance );
		skewness[ i ] = Double.compare( variance, 0d ) == 0 ? 0 :
			((sum3 - 3.0 * mean[ i ] * sum2 ) / voxelCount
				+ 2.0 * mean[ i ] * mean2 ) / ( variance * sDeviation );
	}

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

	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 the minimum intensity values of the neighbor labels
 *
 * @return result table with minimum values of neighbor labels
 */
public ResultsTable getNeighborsMin()
{
	// Check if adjacency list has been created
	if( this.adjList == null )
		this.adjList = RegionAdjacencyGraph.computeAdjacencies( labelImage );

	final int numLabels = objectVoxels.length;

	// check if the minimum intensity of individual labeled regions
	// has been already calculated
	if( null == this.min )
		this.min = minPerLabel();

	// Initialize array of adjacent minimum values
	double[] adjacentMin = new double[ numLabels ];
	for( int i=0; i<numLabels; i++ )
		adjacentMin[ i ] = Double.NaN;

	// go through list of adjacent pairs
	for( LabelPair pair : adjList )
	{
		// extract their indices
		int ind1 = super.labelIndices.get( pair.label1 );
		int ind2 = super.labelIndices.get( pair.label2 );

		// store minimum value of adjacent label voxels
		if( Double.isNaN( adjacentMin[ ind1 ] ) )
			adjacentMin[ ind1 ] = Double.MAX_VALUE;
		if( Double.isNaN( adjacentMin[ ind2 ] ) )
			adjacentMin[ ind2 ] = Double.MAX_VALUE;

		// check if the minimum value of the adjacent neighbor
		// is smaller than the stored minimum (in both directions)
		if( this.min[ ind2 ] < adjacentMin[ ind1 ] )
			adjacentMin[ ind1 ] = this.min[ ind2 ];

		if( this.min[ ind1 ] < adjacentMin[ ind2 ] )
			adjacentMin[ ind2 ] = this.min[ ind1 ];
	}

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

	return table;
}
 
Example 20
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the false positive error between two label images (source and target)
 * per each individual labeled region.
 * <p>
 * False Positive Error (for each individual labeled region r) $FN_r = \frac{ |S_r \setminus T_r| }{ |S_r| }$.
 * @param sourceImage source label image
 * @param targetImage target label image
 * @return false positive error per label or null if error
 * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a>
 */
public static final ResultsTable getFalsePositiveErrorPerLabel(
		ImageStack sourceImage,
		ImageStack targetImage )
{
	if( sourceImage.getWidth() != targetImage.getWidth() ||
			sourceImage.getHeight() != targetImage.getHeight() ||
			sourceImage.getSize() != targetImage.getSize() )
		return null;
	int[] sourceLabels = findAllLabels( sourceImage );
	double[] setDiff = new double[ sourceLabels.length ];
	// create associative array to identify the index of each label
    HashMap<Integer, Integer> sourceLabelIndices = mapLabelIndices( sourceLabels );
    int[] numPixSource = voxelCount( sourceImage, sourceLabels );

    // calculate the set difference between source and target
    for( int k = 0; k < sourceImage.getSize(); k++ )
 	{
 		final ImageProcessor ls = sourceImage.getProcessor( k+1 );
 		final ImageProcessor lt = targetImage.getProcessor( k+1 );
 		for( int i = 0; i < sourceImage.getWidth(); i++ )
 			for( int j = 0; j < sourceImage.getHeight(); j++ )
 				if( ls.getf( i, j ) > 0 ) // skip label 0 (background)
 				{
 					if( ls.getf( i, j ) != lt.getf( i, j ) )
 						setDiff[ sourceLabelIndices.get( (int) ls.getf( i, j ) ) ] ++;
 				}
 	}

    // return the false positive error
    for( int i = 0; i < setDiff.length; i ++ )
    	setDiff[ i ] /= numPixSource[ i ];

    // 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( "FalsePositiveError", setDiff[ i ] );
 		}
 	    return table;
}