예제 #1
0
        /// <summary>
        /// Implements an 8-connected region growing algorithm based on histogram similarity (using back projection).
        /// Starts with the starting pixel and checks in the back projection all the four pixel around it.
        /// If the pixels pass some threshold, they are selected and the region is grown to contain them as well.
        /// </summary>
        public static void Fill(Point startPoint, CVImage outputImage,
                                RegionGrowingCriteria criteria, object criteriaCookie,
                                LabelingFunc labelFunc, object labelingCookie)
        {
            // first, include the starting pixel in the region.
            labelFunc(outputImage, startPoint, labelingCookie);

            // go over all the connection points.
            foreach (Point connection in connections)
            {
                Point connectionPoint = new Point(
                    startPoint.X + (int)connection.X,
                    startPoint.Y + (int)connection.Y);

                if (!outputImage.Contains(connectionPoint))
                {
                    continue;
                }

                // consider this point only if it's not already in the region.
                if (outputImage[connectionPoint].GrayLevel != 0)
                {
                    continue;
                }

                // only if growing criteria is met, recurse away.
                if (criteria(startPoint, connectionPoint, criteriaCookie))
                {
                    // recurse into the new connection point.
                    Fill(connectionPoint, outputImage, criteria, criteriaCookie, labelFunc, labelingCookie);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Implements an 8-connected region growing algorithm based on histogram similarity (using back projection).
        /// Starts with the starting pixel and checks in the back projection all the four pixel around it.
        /// If the pixels pass some threshold, they are selected and the region is grown to contain them as well.
        /// </summary>
        public static void Fill(Point startPoint, CVImage outputImage, 
            RegionGrowingCriteria criteria, object criteriaCookie,
            LabelingFunc labelFunc, object labelingCookie)
        {
            // first, include the starting pixel in the region.
            labelFunc(outputImage, startPoint, labelingCookie);

            // go over all the connection points.
            foreach (Point connection in connections)
            {
                Point connectionPoint = new Point(
                        startPoint.X + (int)connection.X,
                        startPoint.Y + (int)connection.Y);

                if (!outputImage.Contains(connectionPoint))
                    continue;

                // consider this point only if it's not already in the region.
                if (outputImage[connectionPoint].GrayLevel != 0) continue;

                // only if growing criteria is met, recurse away.
                if (criteria(startPoint, connectionPoint, criteriaCookie))
                {
                    // recurse into the new connection point.
                    Fill(connectionPoint, outputImage, criteria, criteriaCookie, labelFunc, labelingCookie);
                }
            }
        }