コード例 #1
0
ファイル: Operators.cs プロジェクト: kutagh/IBV
 /// <summary>
 /// Calculates the circularity of every object in a labeled image.
 /// </summary>
 /// <param name="image">A labeled image to process</param>
 /// <returns>A Dictionary with circularity per color label</returns>
 public static Dictionary<Color, double> Circularity(this Color[,] image)
 {
     return image.Areas().Zip(image.Perimeters(), (A, l) => new KeyValuePair<Color, double>(A.Key, (4 * Math.PI * A.Value) / (l.Value * l.Value))).ToDictionary(x => x.Key, x => x.Value);
 }
コード例 #2
0
ファイル: Operators.cs プロジェクト: kutagh/IBV
        public static Dictionary<Color, double> ObjectRectangularity(this Color[,] image)
        {
            Dictionary<Color, double> result = new Dictionary<Color, double>();
            Dictionary<Color, int> areas = image.Areas();
            Dictionary<Color, Rectangle> bounds = image.BoundingBox();

            foreach ( Color key in areas.Keys )
                result.Add(key, areas[key] / (double)( bounds[key].Height * bounds[key].Width ) );

            /*
            Dictionary<Color, Rectangle> bounds = image.BoundingBox();
            Dictionary<Color, int> areas = image.Areas();
            Dictionary<Color, double> result = bounds.ToDictionary(x => x.Key, x => (double)area[x.Key] / (double)( x.Value.Width * x.Value.Height ));*/

            return result;
        }
コード例 #3
0
ファイル: Operators.cs プロジェクト: kutagh/IBV
        /// <summary>
        /// 
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Dictionary<Color, Tuple<double, double>> Centroids(this Color[,] image)
        {
            var areas = image.Areas();
            var xCentroids = image.MomentOfOrder(1, 0).Zip(areas, (a, b) => new KeyValuePair<Color, double>(a.Key, a.Value / b.Value));
            var yCentroids = image.MomentOfOrder(0, 1).Zip(areas, (a, b) => new KeyValuePair<Color, double>(a.Key, a.Value / b.Value));

            return xCentroids.Zip(yCentroids, (a, b) => new KeyValuePair<Color, Tuple<double, double>>(a.Key, new Tuple<double, double>(a.Value, b.Value))).ToDictionary(x => x.Key, x => x.Value);
        }