예제 #1
0
        public void calculateGradientImageTest()   //Проверка подсчета градиентов на картинке
        {
            //arrange
            IParser       parser = new Parser();
            Bitmap        bitmap = parser.readPNG("Data\\sample_10.png");
            IMathematical strat  = new MathematicialSearchPoint1();  //Подсчет градиента первой стратегией

            strat.setImage(bitmap);

            Elimination elemenation = new Elimination(strat);

            Data.Image img = new Data.Image("Data\\sample_10.png");

            //act
            elemenation.calculateGradientImage(img);
            double[,] exepected = new double[img.width(), img.height()];
            double[,] actual    = elemenation.swingSharpness;

            //assert
            for (int i = 0; i < img.width(); i++)
            {
                for (int j = 0; j < img.height(); j++)
                {
                    Assert.AreEqual(strat.gradientAtPoint(i, j), actual[i, j]);
                }
            }
        }
예제 #2
0
        public void calculateGradientImage(Data.Image image)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];
                for (int x = 0; x < image.width(); x++)
                {
                    for (int y = 0; y < image.height(); y++)
                    {
                        swingSharpness[x, y] = -255;
                    }
                }
            }

            curentImage = image.image;
            curentImage = changeImage.translateToMonochrome(curentImage);
            matematical.setImage(curentImage);

            /*
             * for (int x = 0; x < image.width(); x++)
             *    for (int y = 0; y < image.height(); y++)
             *    {
             *        double gradient = matematical.gradientAtPoint(x, y);
             *        if (gradient > swingSharpness[x, y])
             *            swingSharpness[x, y] = gradient;
             *    }
             */
            Parallel.For(0, 4, calculateGradientImage);
        }
예제 #3
0
        public void clarifySolution(Data.Image image)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];
                for (int x = 0; x < image.width(); x++)
                {
                    for (int y = 0; y < image.height(); y++)
                    {
                        swingSharpness[x, y] = 0;
                    }
                }
                width  = image.width();
                height = image.height();
            }

            List <Data.Point> listPoint   = new List <Data.Point>();
            Bitmap            curentImage = image.image;

            curentImage = changeImage.translateToMonochrome(curentImage);
            matematical.setImage(curentImage);
            for (int x = 0; x < image.width(); x++)
            {
                for (int y = 0; y < image.height(); y++)
                {
                    double gradient = matematical.gradientAtPoint(x, y);
                    if (gradient > swingSharpness[x, y])
                    {
                        listPoint.Add(new Data.Point(x, y));
                        swingSharpness[x, y] = gradient;
                    }
                }
            }
            solution.setValue(listPoint, image);
        }
예제 #4
0
        public void getSolutionTest()          //Проверка отсева (получения хороших точек)
        {
            //Хорошая точка-значение градиента больше порогового значения
            //arrange
            IMathematical strat       = new MathematicialSearchPoint1();
            Elimination   elemenation = new Elimination(strat);

            Data.Image img = new Data.Image("Data\\sample_10.png");
            elemenation.calculateGradientImage(img);      //Вычисление градиента
            //act
            double maxGradient = elemenation.swingSharpness[0, 0];
            double minGradient = elemenation.swingSharpness[0, 0];

            for (int i = 0; i < img.width(); i++)       //Найти макс и мин
            {
                for (int j = 0; j < img.height(); j++)
                {
                    maxGradient = Math.Max(maxGradient, elemenation.swingSharpness[i, j]);
                    minGradient = Math.Min(minGradient, elemenation.swingSharpness[i, j]);
                }
            }
            double            threshold = minGradient + ((maxGradient - minGradient) * 0.1); //порог
            List <Data.Point> exepected = new List <Data.Point>();

            for (int i = 0; i < img.width(); i++)
            {
                for (int j = 0; j < img.height(); j++)
                {
                    if (elemenation.swingSharpness[i, j] >= threshold)
                    {
                        exepected.Add(new Data.Point(i, j));
                    }
                }
            }

            List <Data.Point> actual = new List <Data.Point>();

            actual = elemenation.getSolution();
            //assert
            Debug.WriteLine("Проверка количества точек");
            Assert.AreEqual(actual.Count, exepected.Count);
            Debug.WriteLine("Проверка самих точек");
            int t = 0;

            foreach (Data.Point p1 in exepected)
            {
                Assert.AreEqual(p1.x, actual[t].x);
                Assert.AreEqual(p1.y, actual[t].y);
                t++;
            }
        }
예제 #5
0
        public void clarifySolution(Data.Image image)
        {
            Random       random    = new Random();
            List <Point> listPoint = new List <Point>();
            //Задаем случайное количество точек попавших в фокус
            int countFocusPoint = random.Next(image.width(), image.width() * image.height());

            for (int i = 0; i < countFocusPoint; i++)
            {
                int   x     = random.Next(1, image.width());
                int   y     = random.Next(1, image.height());
                Point point = new Point(x, y);
                listPoint.Add(point);
            }

            solution.setValue(listPoint, image);
        }
예제 #6
0
 public void setValue(List <Point> coordinate, Image image)
 {
     if (nullSolution)
     {
         createdBeginSolution(image.width(), image.height());
     }
     foreach (Point point in coordinate)
     {
         mapHeights[point.x, point.y] = image.tall;
         _sharpImage.SetPixel(point.x, point.y, image.GetPixel(point.x, point.y));
     }
 }
예제 #7
0
        public void widthTest()            //Проверка получения ширины изображения в пикселях
        {
            //arrange
            Data.Image img = new Data.Image("Data\\sample_01.png");

            //act
            double widh = img.width();

            //assert
            Debug.WriteLine("Проверка ширины");
            Assert.AreEqual(widh, 20);
        }
예제 #8
0
        public void clarifySolution(Data.Image image, List <IMathematical> coreGoodPoint, List <Data.Point> goodPoint)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];

                /*  for (int x = 0; x < image.width(); x++)
                 *    for (int y = 0; y < image.height(); y++)
                 *        swingSharpness[x, y] = 0;*/
                width  = image.width();
                height = image.height();
            }

            List <Data.Point> listPoint   = new List <Data.Point>();
            Bitmap            curentImage = image.image;

            curentImage = changeImage.translateToMonochrome(curentImage);
            HashSet <IMathematical> set = new HashSet <IMathematical>(coreGoodPoint);

            foreach (var i in set)
            {
                i.setImage(curentImage);
            }
            for (int i = 0; i < goodPoint.Count; i++)
            {
                int x = goodPoint[i].x;
                int y = goodPoint[i].y;
                matematical = set.First(item => item.GetType() == coreGoodPoint[i].GetType());

                double gradient = matematical.gradientAtPoint(x, y);
                if (gradient > swingSharpness[x, y])
                {
                    listPoint.Add(new Data.Point(x, y));
                    swingSharpness[x, y] = gradient;
                }
            }
            solution.setValue(listPoint, image);
        }
예제 #9
0
        public void GetPixelTest()        //Проверка получения цвета пикселя изображения
        {
            //arrange
            Data.Image img = new Data.Image("Data\\sample_01.png");

            //act

            //assert
            Debug.WriteLine("Проверка цвета пикселя");
            for (int i = 0; i < img.width(); i++)        //По всем пикселям
            {
                for (int j = 0; j < img.height(); j++)
                {
                    Assert.AreEqual(img.GetPixel(i, j), Color.FromArgb(0, 0, 0));
                }
            }
        }