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

The following examples show how to use ij.measure.ResultsTable#incrementCounter() . 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: IntrinsicVolumesAnalyzer3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ResultsTable createTable(Map<Integer, 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));

        // add each measure
        table.addValue("Volume", res.volume);
        table.addValue("SurfaceArea", res.surfaceArea);
        table.addValue("MeanBreadth", res.meanBreadth);
        table.addValue("EulerNumber", res.eulerNumber);
    }

    return table;
}
 
Example 2
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 3
Source File: LabeledVoxelsMeasure.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
	 * Get sum of all voxel intensities per labeled object
	 * 
	 *  @return sum of voxel intensities (Integrated Density) per labeled object
	 */
	public ResultsTable getSumOfVoxels() 
	{
		final int numLabels = objectVoxels.length;

		// create data table
		ResultsTable table = new ResultsTable();
		for (int i = 0; i < numLabels; i++)
		{
			table.incrementCounter();
			table.addLabel(Integer.toString( labels[i] ));
//			double vox_sum = objectVoxels[ i ].stream().mapToDouble(Double::doubleValue).sum();
			// compute the sum, 1.6-compatible
			double voxelSum = 0;
			for (double value : objectVoxels[i])
			{
				voxelSum += value;
			}
			table.addValue( "Voxels Sum", voxelSum);
		}
			return table;
	}
 
Example 4
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 5
Source File: RegionAdjacencyGraphPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ResultsTable createTable(Set<LabelPair> adjList)
{
	ResultsTable table = new ResultsTable();
	table.setPrecision(0);
	
	// populate the table with the list of adjacencies
	for (LabelPair pair : adjList)
	{
		table.incrementCounter();
		table.addValue("Label 1", pair.label1);
		table.addValue("Label 2", pair.label2);
	}
	
	return table;
}
 
Example 6
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get minimum voxel values per label
 * 
 * @return result table with minimum values per label
 */
public ResultsTable getMin()
{
	this.min = minPerLabel();

	// 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("Min", min[i]);
	}

	return table;
}
 
Example 7
Source File: IntensityMeasures.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get mode voxel values per label
 *
 * @return result table with mode values per label
 */
public ResultsTable getMode()
{
	final int numLabels = objectVoxels.length;
	double[] mode = new double[ numLabels ];

	// calculate histogram of each label
	if( null == histogramPerLabel )
		this.histogramPerLabel = getHistogramPerLabel();

	// calculate mode voxel value per object
	for( int i=0; i<numLabels; i++ )
	{
		int max = 1;
		double temp = objectVoxels[ i ].get( 0 );

		for( HashMap.Entry<Double, Integer> entry : histogramPerLabel[ i ].entrySet() )
		{
			if( entry.getValue() > max )
			{
				max = entry.getValue();
				temp = entry.getKey();
			}
		}
		mode[ i ] = temp;
	}

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

	return table;
}
 
Example 8
Source File: MicrostructureAnalysisPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 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 a new ResultsTable containing microstructure characterization of binary image
*/
  public ResultsTable process(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);
      }
 	
      // return the created table
      return table;
  }
 
Example 9
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 10
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 11
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 12
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 13
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
 * 2 directions (horizontal and vertical).
 * 
 * @param image
 *            the input binary image
 * @param resol
 *            the spatial resolution
 * @return an array containing for each label, an estimate of the region perimeter
 */
@Deprecated
private static final ResultsTable perimeterDensity_D2(ImageProcessor image,
		double[] resol) 
{

	// Create data table
	ResultsTable table = new ResultsTable();
	double perim;

	double d1 = resol[0];
	double d2 = resol[1];

	// 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);

	// Compute weighted diameters and multiplies by associated
	// direction weights
	double wd1 = n1 / d1 * weights[0];
	double wd2 = n2 / d2 * weights[1];

	// Compute perimeter
	perim = (wd1 + wd2) * 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);
	}

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

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

	return table;
}
 
Example 14
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(
		ImageProcessor labelImage1,
		ImageProcessor labelImage2 )
{
	if( labelImage1.getWidth() != labelImage2.getWidth() ||
			labelImage1.getHeight() != labelImage2.getHeight() )
		return null;

	int[] labels1 = findAllLabels( labelImage1 );
	int[] numPix1 = pixelCount( 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 = pixelCount( labelImage2, labels2 );

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

	// calculate the pixel to pixel intersection
    for( int i = 0; i < labelImage1.getWidth(); i++ )
    	for( int j = 0; j < labelImage1.getHeight(); j++ )
    		if( labelImage1.getf( i, j ) > 0 ) // skip label 0 (background)
    		{
    			if( labelImage1.getf( i, j ) == labelImage2.getf( i, j ) )
    				intersection[ labelIndices1.get( (int) labelImage1.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 15
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};
  }
 
Example 16
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the Jaccard index per label (intersection over union overlap) between
 * two label images.
 * @param labelImage1 reference label image
 * @param labelImage2 label image to compare with
 * @return Jaccard index per label in the reference image or null if error
 * @see <a href="https://en.wikipedia.org/wiki/Jaccard_index">https://en.wikipedia.org/wiki/Jaccard_index</a>
 */
public static final ResultsTable getJaccardIndexPerLabel(
		ImageProcessor labelImage1,
		ImageProcessor labelImage2 )
{
	if( labelImage1.getWidth() != labelImage2.getWidth() ||
			labelImage1.getHeight() != labelImage2.getHeight() )
		return null;

	int[] labels1 = findAllLabels( labelImage1 );
	int[] numPix1 = pixelCount( 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 = pixelCount( labelImage2, labels2 );

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

	// calculate the pixel to pixel intersection
    for( int i = 0; i < labelImage1.getWidth(); i++ )
    	for( int j = 0; j < labelImage1.getHeight(); j++ )
    		if( labelImage1.getf( i, j ) > 0 ) // skip label 0 (background)
    		{
    			if( labelImage1.getf( i, j ) == labelImage2.getf( i, j ) )
    				intersection[ labelIndices1.get( (int) labelImage1.getf( i, j ) ) ] ++;
    		}
    // return the intersection over the union
    for( int i = 0; i < intersection.length; i ++ )
    {
    	int num2 = labelIndices2.get( labels1[ i ] ) != null ? numPix2[ labelIndices2.get( labels1[ i ] ) ] : 0;
    	intersection[ i ] /= ( numPix1[ i ] + num2 - intersection[ i ] );
    }
    // 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("JaccardIndex", intersection[i]);
		}
	    return table;
}
 
Example 17
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 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: 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 20
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");
	}
}