Example #1
0
        public override ICData Run()
        {
            List<Point> sourcePoints = Utilities.ExtractPoints(m_Image1, TresholdColor);
            List<Point> targetPoints = Utilities.ExtractPoints(m_Image2, TresholdColor);
            m_sourceMatrix = Utilities.ListToMatrix(sourcePoints);
            m_targetMatrix = Utilities.ListToMatrix(targetPoints);

            m_commonSize = new Size(Math.Max(m_Image1.Width, m_Image2.Width), Math.Max(m_Image1.Height, m_Image2.Height));

            PCAMatching matching = new PCAMatching(new DoubleMatrix((Matrix<double>)m_sourceMatrix.Clone()), m_targetMatrix);
            matching.Calculate();

            CPCAresultData retResult = new CPCAresultData(m_sourceMatrix, matching.Result, m_commonSize, matching);
            retResult.IncludeSource = IncludeSource;
            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;
        }
Example #3
0
 public CPCAresultData(DoubleMatrix i_Source,DoubleMatrix i_Target,Size i_ImageSize,PCAMatching i_matching)
 {
     ///Determine global shifting if required, and calculating the image size according to manipulated data
     m_CommonSize = ShiftToPozitives(ref i_Source, ref i_Target, i_ImageSize);
     ///Creating new bitmap and setting fields
     m_ResultlingBitmap = new Bitmap(m_CommonSize.Width, m_CommonSize.Height);
     m_Source = i_Source;
     m_Target = i_Target;
     SourceColor = Utilities.sr_defaultSourceColor;
     TargetColor = Utilities.sr_defaultTargetColor;
     m_Matching = i_matching;
 }