Accord.Imaging.BorderFollowing.FindContour C# (CSharp) Method

FindContour() public method

Extracts the contour from a single object in a grayscale image.
public FindContour ( Bitmap image ) : List
image System.Drawing.Bitmap A grayscale image.
return List
        public List<IntPoint> FindContour(Bitmap image)
        {
            // lock source bitmap data
            BitmapData srcData = image.LockBits(
                new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);

            List<IntPoint> contour = null;

            try
            {
                // extract image contour
                contour = FindContour(srcData);
            }
            finally
            {
                // unlock source image
                image.UnlockBits(srcData);
            }

            return contour;
        }

Same methods

BorderFollowing::FindContour ( BitmapData image ) : List
BorderFollowing::FindContour ( UnmanagedImage image ) : List

Usage Example

Example #1
0
        public void FindPeaksTest()
        {
            Bitmap hand = Properties.Resources.rhand;

            GaussianBlur median = new GaussianBlur(1.1);
            median.ApplyInPlace(hand);

            // Extract contour
            BorderFollowing bf = new BorderFollowing(1);
            List<IntPoint> contour = bf.FindContour(hand);

            hand = hand.Clone(new Rectangle(0, 0, hand.Width, hand.Height), PixelFormat.Format24bppRgb);

            // Find peaks
            KCurvature kcurv = new KCurvature(30, new DoubleRange(0, 45));
            // kcurv.Suppression = 30;
            var peaks = kcurv.FindPeaks(contour);

            List<IntPoint> supports = new List<IntPoint>();
            for (int i = 0; i < peaks.Count; i++)
            {
                int j = contour.IndexOf(peaks[i]);
                supports.Add(contour[(j + kcurv.K) % contour.Count]);
                supports.Add(contour[Accord.Math.Tools.Mod(j - kcurv.K, contour.Count)]);
            }

            // show(hand, contour, peaks, supports);

            Assert.AreEqual(2, peaks.Count);
            Assert.AreEqual(46, peaks[0].X);
            Assert.AreEqual(0, peaks[0].Y);
            Assert.AreEqual(2, peaks[1].X);
            Assert.AreEqual(11, peaks[1].Y);
        }
All Usage Examples Of Accord.Imaging.BorderFollowing::FindContour