Exemplo n.º 1
0
        public override ICData Run()
        {
            int prevNumberOfSamples = NumberOfSamples;

            if (NumberOfSamples == Utils.sr_NoInit)
            {                                                                                  ///if no amount of samples is set
                NumberOfSamples = Math.Min(m_sourcePoints.Length, m_targetPoints.Length) / 50; ///Hard reduction
            }

            #region Default params override

            if (NumberOfIterations != Utils.sr_NoInit)
            {
                m_matching.NumOfIterations = NumberOfIterations;
            }
            if (NumberOfBins != Utils.sr_NoInit)
            {
                m_matching.NumOfBins = NumberOfBins;
            }
            if (NumberOfThetaBins != Utils.sr_NoInit)
            {
                m_matching.NumOfThetaBins = NumberOfThetaBins;
            }

            #endregion

            if (UseStandardAlignment)
            {
                m_matching.AlignmentLogic = m_matching.StandardAlignmentLogic;
            }

            m_matching.Calculate();

            CShapeContextResultData retResult = new CShapeContextResultData(
                m_sourcePoints,
                m_matching.ResultPoints,
                m_commonSize,
                m_matching.LastSourceSamples,
                m_matching.LastTargetSamples
                );

            retResult.IncludeSource             = IncludeSource;
            retResult.MatchesColoringConvension = ColoringMatchesLogic;
            NumberOfSamples = prevNumberOfSamples;
            return(retResult);
        }
        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;
        }
Exemplo n.º 3
0
        public override ICData Run()
        {
            int prevNumberOfSamples = NumberOfSamples;
            if (NumberOfSamples == Utils.sr_NoInit)
            {///if no amount of samples is set
                NumberOfSamples = Math.Min(m_sourcePoints.Length, m_targetPoints.Length) / 50; ///Hard reduction
            }

            #region Default params override

            if (NumberOfIterations != Utils.sr_NoInit)
            {
                m_matching.NumOfIterations = NumberOfIterations;
            }
            if (NumberOfBins != Utils.sr_NoInit)
            {
                m_matching.NumOfBins = NumberOfBins;
            }
            if (NumberOfThetaBins!= Utils.sr_NoInit)
            {
                m_matching.NumOfThetaBins = NumberOfThetaBins;
            }

            #endregion

            if (UseStandardAlignment)
            {
                m_matching.AlignmentLogic = m_matching.StandardAlignmentLogic;
            }

            m_matching.Calculate();

            CShapeContextResultData retResult = new CShapeContextResultData(
                m_sourcePoints,
                m_matching.ResultPoints,
                m_commonSize,
                m_matching.LastSourceSamples,
                m_matching.LastTargetSamples
                );

            retResult.IncludeSource = IncludeSource;
            retResult.MatchesColoringConvension = ColoringMatchesLogic;
            NumberOfSamples = prevNumberOfSamples;
            return retResult;
        }
Exemplo n.º 4
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);
        }