示例#1
0
 private void FindNearestNeighbourForAllPoints(ref ImageParametrs firstImageParametrs, ref ImageParametrs secondImageParametrs)
 {
     foreach (var pointIndex in firstImageParametrs.allPointAttributes.Keys)
     {
         FindNearestNeighbour(pointIndex, ref firstImageParametrs, secondImageParametrs);
     }
 }
示例#2
0
        private void buttonFindKNN_Click(object sender, EventArgs e)
        {
            ImageParametrs firstImageParametrs  = FileReader.ReadParametrs(1);
            ImageParametrs secondImageParametrs = FileReader.ReadParametrs(2);

            ImageWorker imageWorker = new ImageWorker();
            List <int>  indexes     = imageWorker.FindKNN(ref firstImageParametrs, ref secondImageParametrs);

            imageWorker.DrawLines(indexes, firstImageParametrs, secondImageParametrs);
        }
示例#3
0
        public void DrawLines(List <int> pairIndexes, ImageParametrs firstImageParametrs, ImageParametrs secondImageParametrs)
        {
            Bitmap bitmap = (Bitmap)Image.FromFile(Parametrs.PATH_TO_WORKING_FILES + Parametrs.MERGED_IMAGE_NAME);

            int secondImageIndex = (int)firstImageParametrs.allPointAttributes[pairIndexes[0]].OtherImageIndex;

            DrawLine(bitmap,
                     firstImageParametrs.allPointAttributes[pairIndexes[0]].PointX,
                     firstImageParametrs.allPointAttributes[pairIndexes[0]].PointY,
                     secondImageParametrs.allPointAttributes[pairIndexes[secondImageIndex]].PointX,
                     secondImageParametrs.allPointAttributes[pairIndexes[secondImageIndex]].PointY
                     );
        }
示例#4
0
        private void FindNearestNeighbour(int firstPointIndex, ref ImageParametrs firstImageParametrs, ImageParametrs secondImageParametrs)
        {
            int    smallestDistanceID = 0;
            double smallestDistance   = double.MaxValue;

            foreach (var secondPointIndex in secondImageParametrs.allPointAttributes.Keys)
            {
                double foundDistance = FindEuclideanDistance(firstImageParametrs.allPointAttributes[firstPointIndex].attributes, secondImageParametrs.allPointAttributes[secondPointIndex].attributes);
                if (smallestDistance > foundDistance)
                {
                    smallestDistance   = foundDistance;
                    smallestDistanceID = secondPointIndex;
                    firstImageParametrs.allPointAttributes[firstPointIndex].SetOtherInageIndex(secondPointIndex);
                }
            }
        }
示例#5
0
        private List <int> FindPointPairs(ImageParametrs firstImageParametrs, ImageParametrs secondImageParametrs)
        {
            List <int> pairIndexes = new List <int>();

            foreach (var pointIndex in firstImageParametrs.allPointAttributes.Keys)
            {
                //firstIndex must point to secondIndex (firstIndex == secondIndex)
                int?firstIndex = firstImageParametrs.allPointAttributes[pointIndex].OtherImageIndex;
                if (firstIndex != null)
                {
                    int?secondIndex = secondImageParametrs.allPointAttributes[(int)firstIndex].OtherImageIndex;
                    //secondIndex must point to firstIndex (secondIndex == firstIndex)
                    if ((int)secondIndex == (int)firstIndex)
                    {
                        //Tuple<int, int> pairPointIndexes = new Tuple<int, int>((int) firstIndex, (int) secondIndex);
                        pairIndexes.Add((int)firstIndex);
                    }
                }
            }
            return(pairIndexes);
        }
示例#6
0
        public static ImageParametrs ReadParametrs(int pictureIndex)
        {
            ImageParametrs parametrs = new ImageParametrs();

            string pathToImage = Parametrs.PATH_TO_WORKING_FILES;

            // first(1) or second(2) image index
            if (pictureIndex == 1)
            {
                pathToImage += Parametrs.FIRST_IMAGE_NAME;
            }
            else
            {
                pathToImage += Parametrs.SECOND_IMAGE_NAME;
            }

            if (File.Exists(pathToImage))
            {
                using (StreamReader reader = File.OpenText(pathToImage))
                {
                    int pointCounter = 0;

                    //skip first two integers
                    reader.ReadLine();
                    reader.ReadLine();

                    string readLine = reader.ReadLine();

                    while (readLine != null)
                    {
                        string[] splitedParametrs = readLine.Split(new char[] { ' ', '\t', '\r', '\n', ';' }, StringSplitOptions.RemoveEmptyEntries);

                        ConvertParametrsFromString(splitedParametrs, pointCounter++, ref parametrs);

                        readLine = reader.ReadLine();
                    }
                }
            }
            return(parametrs);
        }
示例#7
0
        private static void ConvertParametrsFromString(string[] splitedParametrs, int pointIndex, ref ImageParametrs parametrs)
        {
            List <int> tmpParametrs = new List <int>();

            for (int i = 5; i < Parametrs.NUMBER_OF_PARAMETRS + 5; i++)
            {
                tmpParametrs.Add(Int32.Parse(splitedParametrs[i]));
            }
            parametrs.AddPointParametr(pointIndex, tmpParametrs, splitedParametrs[0], splitedParametrs[1]);
        }
示例#8
0
 public List <int> FindKNN(ref ImageParametrs firstImageParametrs, ref ImageParametrs secondImageParametrs)
 {
     FindNearestNeighbourForAllPoints(ref firstImageParametrs, ref secondImageParametrs);
     FindNearestNeighbourForAllPoints(ref secondImageParametrs, ref firstImageParametrs);
     return(FindPointPairs(secondImageParametrs, firstImageParametrs));
 }