Пример #1
0
        private static Parameters CalculateParameter(LabelGroup group, int[,] labels)
        {
            var result = new Parameters
                {
                    Square = group.Pixels.Count
                };

            int x = 0, y = 0, perimeter = 0;
            foreach (var item in group.Pixels)
            {
                if (IsBorderPixel(item.X, item.Y, ref labels))
                {
                    perimeter++;
                }
                x += item.X;
                y += item.Y;
            }
            result.SchtynhMasses = new Coords(x/result.Square, y/result.Square);
            result.Perimeter = perimeter;
            result.Density = (double)result.Perimeter*result.Perimeter / result.Square;

            var m20 = DiscretMoment(result.SchtynhMasses.X, result.SchtynhMasses.Y, group.Pixels, 2, 0);
            var m02 = DiscretMoment(result.SchtynhMasses.X, result.SchtynhMasses.Y, group.Pixels, 0, 2);
            var m11 = DiscretMoment(result.SchtynhMasses.X, result.SchtynhMasses.Y, group.Pixels, 1, 1);

            var sqrt = Math.Sqrt(Math.Pow(m20 - m02, 2) + 4*m11*m11);
            result.Elongation = (m20 + m02 + sqrt)/(m20 + m02 - sqrt);
            result.Theta = Math.Atan(2*m11/(m20 - m02)) / 2;
            result.Pixels = group.Pixels;

            return result;
        }
Пример #2
0
        private static double SearchDistance(Parameters parameter, Parameters medoid)
        {
            var avgSquare = (double)(parameter.Square - medoid.Square);//medoid.Square;
            var avgElongation = (parameter.Elongation - medoid.Elongation);//medoid.Elongation;
            var avgPerimeter = (double)(parameter.Perimeter - medoid.Perimeter);//medoid.Perimeter;
            var avgDensity = (parameter.Density - medoid.Density);//medoid.Density;

            return Math.Sqrt(Math.Pow(avgSquare, 2) + Math.Pow(avgElongation, 2) +  Math.Pow(avgPerimeter, 2) + Math.Pow(avgDensity, 2));
        }