コード例 #1
0
        private void InitDistances(ref IntMatrix o_DistMatrix, IntMatrix i_BinaryMapBase)
        {
            Func <int, int, int, int> ToDifferentSizedCopy = (row, col, val) =>
            {///Building a logic for one cell
                if (row <= i_BinaryMapBase.RowsCount && col <= i_BinaryMapBase.ColumnsCount)
                {
                    int baseVale = i_BinaryMapBase[row, col];
                    if (baseVale == 1)
                    {
                        return(0);
                    }
                    else if (baseVale == 0)
                    {
                        return(Int16.MaxValue);
                    }
                    else
                    {
                        throw new HausdorffMatchingException("A non binary value found in a binary matrix!!! Non binary values are not allowed!");
                    }
                }
                else
                {
                    return(0);
                }
            };

            ///Apllying the logic for whole matrix
            o_DistMatrix.Iterate(ToDifferentSizedCopy);
        }
コード例 #2
0
ファイル: Utilities.cs プロジェクト: GRSEB9S/shape-matching-2
        public static IntMatrix ToBinaryMap(Image i_GrayScaleImage, Color i_Treshold, Size i_newCanvasSize)
        {
            IntMatrix retBinaryMap = new IntMatrix(i_newCanvasSize.Height, i_newCanvasSize.Width);
            Bitmap    bitmap       = new Bitmap(i_GrayScaleImage);
            ///Logic for single cell
            Func <int, int, int, int> filterBlacks = (row, col, val) =>
            {
                if (row < bitmap.Height && col < bitmap.Width)
                {
                    Color currColor = bitmap.GetPixel(col, row);
                    if (currColor.R < i_Treshold.R &&
                        currColor.G < i_Treshold.G &&
                        currColor.B < i_Treshold.B)
                    {
                        return(sr_Line);
                    }
                    else
                    {
                        return(sr_NoLine);
                    }
                }
                else
                {
                    return(sr_NoLine);
                }
            };

            ///Applying logic for whole matrix
            retBinaryMap.Iterate(filterBlacks);

            return(retBinaryMap);
        }
コード例 #3
0
ファイル: Utilities.cs プロジェクト: GRSEB9S/shape-matching-2
        public static int DetermineMax(IntMatrix i_Matrix)
        {
            int             retMax    = int.MinValue;
            Func <int, int> maxFinder = (Value) =>
            {
                retMax = Math.Max(retMax, Value);
                return(Value);
            };

            i_Matrix.Iterate(maxFinder);
            return(retMax);
        }
コード例 #4
0
ファイル: Utilities.cs プロジェクト: GRSEB9S/shape-matching-2
        public static Bitmap ToBitmap(IntMatrix i_Matrix, HausdorffMatchingResult.ColoringConvension ColoringFunction)
        {
            Bitmap retBitmap = new Bitmap(i_Matrix.ColumnsCount, i_Matrix.RowsCount);
            int    LocalMax  = DetermineMax(i_Matrix);
            //Logic for single cell
            Func <int, int, int, int> bitmapSet = (row, col, val) =>
            {
                retBitmap.SetPixel(col, row, ColoringFunction(val, LocalMax));
                return(val);
            };

            ///Applying logic for each cell
            i_Matrix.Iterate(bitmapSet);

            return(retBitmap);
        }
コード例 #5
0
        private Queue <Point> binaryToQueue(IntMatrix i_Surface)
        {
            Queue <Point>             retQueue     = new Queue <Point>();
            Func <int, int, int, int> onesToPoints = (row, col, val) =>
            {
                if (val == 1)
                {
                    retQueue.Enqueue(new Point(col, row));
                    return(val);
                }
                else if (val == 0)
                {
                    return(0);
                }

                throw new HausdorffMatchingException("A non binary value found in a binary matrix!!! Non binary values are not allowed!");
            };

            i_Surface.Iterate(onesToPoints);

            return(retQueue);
        }
コード例 #6
0
        public override ICData Run()
        {
            Size StartingCommonSize = new Size(Math.Max(m_Image1.Width, m_Image2.Width), Math.Max(m_Image1.Height, m_Image2.Height));
            //Preparing structures
            List <Point> sourcePoints = Utilities.ExtractPoints(m_Image1, TresholdColor);
            List <Point> targetPoints = Utilities.ExtractPoints(m_Image2, TresholdColor);

            DoubleMatrix source = Utilities.ListToMatrix(sourcePoints);
            DoubleMatrix target = Utilities.ListToMatrix(targetPoints);

            //1st station, PCA alignment
            ////////////////////////////
            PCAMatching pcaMatching = new PCAMatching(source, target);

            pcaMatching.Calculate();

            target = pcaMatching.Result;

            //In between stages
            DoubleMatrix minMax = PCA.Utils.ShiftToPositives(ref target, source);

            minMax = PCA.Utils.ShiftToPositives(ref source, target);

            sourcePoints = Utilities.MatrixToList(source);
            targetPoints = Utilities.MatrixToList(target);

            m_sourcePtArray = sourcePoints.ToArray();
            m_targetPtArray = targetPoints.ToArray();

            Size meshSize = new Size(
                Math.Max((int)Math.Ceiling(minMax[sr_X, sr_MaxCol] + 2), StartingCommonSize.Width),
                Math.Max((int)Math.Ceiling(minMax[sr_Y, sr_MaxCol] + 2), StartingCommonSize.Height));

            //2nd station,Hausdorff Matching Points insertion
            //////////////////////////////////////////////////
            IntMatrix sourceBinaryMap = Utilities.ToBinaryMap(source, meshSize);
            IntMatrix targetBinaryMap = Utilities.ToBinaryMap(target, meshSize);

            HausdorffMatching hausdorffMatching = new HausdorffMatching(sourceBinaryMap, targetBinaryMap);
            IntMatrix         diffSource        = hausdorffMatching.Calculate1on2();
            IntMatrix         diffTarget        = hausdorffMatching.Calculate2on1();

            //Preparing a logic for point selection bank
            List <Point> currList = null;
            Func <int, int, int, int> pointInsertionLogic = (row, col, value) =>
            {
                for (int i = 2; i < value; ++i)
                {
                    currList.Add(new Point(col, row));
                }
                return(value);
            };

            //Applying this logic
            m_SourceBank = new List <Point>();
            currList     = m_SourceBank;
            diffSource.Iterate(pointInsertionLogic);
            m_TargetBank = new List <Point>();
            currList     = m_TargetBank;
            diffTarget.Iterate(pointInsertionLogic);

            //3rd station ShapeContext Matching
            ///////////////////////////////////
            ShapeContextMatching shapeContextMatching = new ShapeContextMatching(m_sourcePtArray, m_targetPtArray, meshSize, SelectSamplesLogic);

            shapeContextMatching.AlignmentLogic = shapeContextMatching.StandardAlignmentLogic;
            if (ShapeContextWarpDistanceTreshold > 0)
            {
                shapeContextMatching.DistanceTreshold = ShapeContextWarpDistanceTreshold;
            }
            shapeContextMatching.Calculate();

            CShapeContextResultData retResult =
                new CShapeContextResultData(
                    m_sourcePtArray,
                    m_targetPtArray,
                    meshSize,
                    shapeContextMatching.LastSourceSamples,
                    shapeContextMatching.LastTargetSamples);

            return(retResult);
        }
コード例 #7
0
        private void InitDistances(ref IntMatrix o_DistMatrix, IntMatrix i_BinaryMapBase)
        {
            Func<int, int, int, int> ToDifferentSizedCopy = (row, col, val) =>
            {///Building a logic for one cell
                if (row <= i_BinaryMapBase.RowsCount && col <= i_BinaryMapBase.ColumnsCount)
                {
                    int baseVale = i_BinaryMapBase[row, col];
                    if (baseVale == 1)
                    {
                        return 0;
                    }
                    else if (baseVale == 0)
                    {
                        return Int16.MaxValue;
                    }
                    else
                    {
                        throw new HausdorffMatchingException("A non binary value found in a binary matrix!!! Non binary values are not allowed!");
                    }
                }
                else
                {
                    return 0;
                }
            };

            ///Apllying the logic for whole matrix
            o_DistMatrix.Iterate(ToDifferentSizedCopy);
        }
コード例 #8
0
        private Queue<Point> binaryToQueue(IntMatrix i_Surface)
        {
            Queue<Point> retQueue = new Queue<Point>();
            Func<int, int, int, int> onesToPoints = (row, col, val) =>
                {
                    if (val == 1)
                    {
                        retQueue.Enqueue(new Point(col, row));
                        return val;
                    }
                    else if (val == 0)
                    {
                        return 0;
                    }

                    throw new HausdorffMatchingException("A non binary value found in a binary matrix!!! Non binary values are not allowed!");
                };

            i_Surface.Iterate(onesToPoints);

            return retQueue;
        }