Example #1
0
 public ObjectParameters(ObjectParameters obj)
 {
     Perimeter = obj.Perimeter;
     Square = obj.Square;
     Compactness = obj.Compactness;
     Xmas = obj.Xmas;
     Ymas = obj.Ymas;
     m20 = obj.m20;
     m02 = obj.m02;
     m11 = obj.m11;
     elongation = obj.elongation;
     OrientationOfMainAxis = obj.OrientationOfMainAxis;
 }
Example #2
0
 private double calculateDistance(ObjectParameters obj, ObjectParameters median)
 {
     double per = Math.Pow(obj.Perimeter - median.Perimeter, 2);
     double sq = Math.Pow(obj.Square - median.Square, 2);
     double el = Math.Pow(obj.elongation - median.elongation, 2);
     double comp = Math.Pow(obj.Compactness - median.Compactness, 2);
  //   double orient = Math.Pow(obj.OrientationOfMainAxis - median.OrientationOfMainAxis, 2);
     return Math.Sqrt(per + sq + el + comp /*+ orient*/);
 }
Example #3
0
        unsafe private void CalculateParameters()
        {
            objects = new ObjectParameters[objectsCount];
            for (int i = 0; i < objects.Length; i++ )
                objects[i] = new ObjectParameters();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int labelIndex = GetLabelIndex(x, y);
                    if (labels[labelIndex] != 0)
                    {
                        objects[labels[labelIndex]].Square++;
                        objects[labels[labelIndex]].Xmas += x;
                        objects[labels[labelIndex]].Ymas += y;

                        if (GetLabelIndex(x + 1, y) < 0 || GetLabelIndex(x + 1, y) >= labels.Length ||
                            GetLabelIndex(x - 1, y) < 0 || GetLabelIndex(x - 1, y) >= labels.Length ||
                            GetLabelIndex(x, y + 1) < 0 || GetLabelIndex(x, y + 1) >= labels.Length ||
                            GetLabelIndex(x, y - 1) < 0 || GetLabelIndex(x, y - 1) >= labels.Length)
                            objects[labels[labelIndex]].Perimeter++;
                        // Связность 4, внутренняя граница
                        else if (labels[GetLabelIndex(x + 1, y)] != labels[labelIndex] || labels[GetLabelIndex(x - 1, y)] != labels[labelIndex]
                            || labels[GetLabelIndex(x, y + 1)] != labels[labelIndex] || labels[GetLabelIndex(x, y - 1)] != labels[labelIndex])
                            objects[labels[labelIndex]].Perimeter++;
                    }
                }
            }
            // Вычисление центра масс и компактности
            for (int i = 1; i < objects.Length; i++)
            {
                objects[i].Xmas /= (double)objects[i].Square;
                objects[i].Ymas /= (double)objects[i].Square;
                objects[i].Compactness = objects[i].Perimeter * objects[i].Perimeter / objects[i].Square;
            }

            // Дискретные центральные моменты
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int labelIndex = GetLabelIndex(x, y);
                    if (labels[labelIndex] != 0)
                    {
                        objects[labels[labelIndex]].m20 += Math.Pow((x - objects[labels[labelIndex]].Xmas), 2);
                        objects[labels[labelIndex]].m02 += Math.Pow((y - objects[labels[labelIndex]].Ymas), 2);
                        objects[labels[labelIndex]].m11 += (x - objects[labels[labelIndex]].Xmas) * (y - objects[labels[labelIndex]].Ymas);
                    }
                }
            }

            // Вычисление удлинённости и ориентаци главной оси
            for (int i = 1; i < objects.Length; i++)
            {
                objects[i].elongation = (objects[i].m20 + objects[i].m02 + Math.Sqrt(Math.Pow((objects[i].m20 - objects[i].m02), 2) + 4 * objects[i].m11 * objects[i].m11)) /
                    (objects[i].m20 + objects[i].m02 - Math.Sqrt(Math.Pow((objects[i].m20 - objects[i].m02), 2) + 4 * objects[i].m11 * objects[i].m11));

                objects[i].OrientationOfMainAxis = 1.0 / 2.0 * Math.Atan(2 * objects[i].m11 / (objects[i].m20 - objects[i].m02));
            }
        }
Example #4
0
 private bool isBadValue(ObjectParameters obj)
 {
     return double.IsNaN(obj.Compactness) || double.IsNaN(obj.elongation) ||
             double.IsNaN(obj.OrientationOfMainAxis) || double.IsNaN(obj.Xmas) ||
             double.IsNaN(obj.Ymas) || double.IsNaN(obj.m02) ||
             double.IsNaN(obj.m20) || double.IsNaN(obj.m11) || double.IsInfinity(obj.Compactness) || 
             double.IsInfinity(obj.elongation) || double.IsInfinity(obj.OrientationOfMainAxis) || 
             double.IsInfinity(obj.Xmas) || double.IsInfinity(obj.Ymas) || double.IsInfinity(obj.m02) ||
             double.IsInfinity(obj.m20) || double.IsInfinity(obj.m11);
 }
Example #5
0
        unsafe private void CalculateParameters()
        {
            objects = new ObjectParameters[objectsCount];
            for (int i = 0; i < objects.Length; i++)
            {
                objects[i] = new ObjectParameters();
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int labelIndex = GetLabelIndex(x, y);
                    if (labels[labelIndex] != 0)
                    {
                        objects[labels[labelIndex]].Square++;
                        objects[labels[labelIndex]].Xmas += x;
                        objects[labels[labelIndex]].Ymas += y;

                        if (GetLabelIndex(x + 1, y) < 0 || GetLabelIndex(x + 1, y) >= labels.Length ||
                            GetLabelIndex(x - 1, y) < 0 || GetLabelIndex(x - 1, y) >= labels.Length ||
                            GetLabelIndex(x, y + 1) < 0 || GetLabelIndex(x, y + 1) >= labels.Length ||
                            GetLabelIndex(x, y - 1) < 0 || GetLabelIndex(x, y - 1) >= labels.Length)
                        {
                            objects[labels[labelIndex]].Perimeter++;
                        }
                        // Связность 4, внутренняя граница
                        else if (labels[GetLabelIndex(x + 1, y)] != labels[labelIndex] || labels[GetLabelIndex(x - 1, y)] != labels[labelIndex] ||
                                 labels[GetLabelIndex(x, y + 1)] != labels[labelIndex] || labels[GetLabelIndex(x, y - 1)] != labels[labelIndex])
                        {
                            objects[labels[labelIndex]].Perimeter++;
                        }
                    }
                }
            }
            // Вычисление центра масс и компактности
            for (int i = 1; i < objects.Length; i++)
            {
                objects[i].Xmas       /= (double)objects[i].Square;
                objects[i].Ymas       /= (double)objects[i].Square;
                objects[i].Compactness = objects[i].Perimeter * objects[i].Perimeter / objects[i].Square;
            }

            // Дискретные центральные моменты
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int labelIndex = GetLabelIndex(x, y);
                    if (labels[labelIndex] != 0)
                    {
                        objects[labels[labelIndex]].m20 += Math.Pow((x - objects[labels[labelIndex]].Xmas), 2);
                        objects[labels[labelIndex]].m02 += Math.Pow((y - objects[labels[labelIndex]].Ymas), 2);
                        objects[labels[labelIndex]].m11 += (x - objects[labels[labelIndex]].Xmas) * (y - objects[labels[labelIndex]].Ymas);
                    }
                }
            }

            // Вычисление удлинённости и ориентаци главной оси
            for (int i = 1; i < objects.Length; i++)
            {
                objects[i].elongation = (objects[i].m20 + objects[i].m02 + Math.Sqrt(Math.Pow((objects[i].m20 - objects[i].m02), 2) + 4 * objects[i].m11 * objects[i].m11)) /
                                        (objects[i].m20 + objects[i].m02 - Math.Sqrt(Math.Pow((objects[i].m20 - objects[i].m02), 2) + 4 * objects[i].m11 * objects[i].m11));

                objects[i].OrientationOfMainAxis = 1.0 / 2.0 * Math.Atan(2 * objects[i].m11 / (objects[i].m20 - objects[i].m02));
            }
        }