Example #1
0
 public bool Equals(FeatureBlob other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.Id == Id);
 }
Example #2
0
        public static IEnumerable <FeatureBlob> DoWatershedAlgorithm(IEnumerable <Point> pointList)
        {
            // First make sure we are ordered by intensity
            pointList = pointList.Where(x => x.Intensity > 0).OrderByDescending(x => x.Intensity);

            List <FeatureBlob> featureList = new List <FeatureBlob>();
            int featureIndex = 0;

            foreach (Point point in pointList)
            {
                FeatureBlob          moreIntenseFeature   = null;
                HigherNeighborResult higherNeighborResult = point.FindMoreIntenseNeighbors(out moreIntenseFeature);

                // If no higher features are found, then seed a new Feature
                if (higherNeighborResult == HigherNeighborResult.None)
                {
                    // Local maximum and will be the seed of a new blob
                    FeatureBlob newFeature = new FeatureBlob(featureIndex);
                    newFeature.PointList.Add(point);
                    point.FeatureBlob = newFeature;
                    featureList.Add(newFeature);
                    featureIndex++;

                    continue;
                }

                // Background or Multiple Features means that this Point will be Background
                if (higherNeighborResult == HigherNeighborResult.Background)
                {
                    point.IsBackground = true;
                    continue;
                }

                // If we get here, then we know the only option is that a single Feature was returned
                moreIntenseFeature.PointList.Add(point);
                point.FeatureBlob = moreIntenseFeature;
            }

            return(featureList);
        }
Example #3
0
        public HigherNeighborResult FindMoreIntenseNeighbors(out FeatureBlob feature)
        {
            var         featureCount = 0;
            FeatureBlob savedFeature = null;

            feature = null;

            if (North != null && North.Intensity >= Intensity)
            {
                if (North.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                savedFeature = North.FeatureBlob;
            }
            if (South != null && South.Intensity >= Intensity)
            {
                if (South.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (South.FeatureBlob != null && savedFeature != South.FeatureBlob)
                    {
                        if (South.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = South.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = South.FeatureBlob;
                }
            }
            if (East != null && East.Intensity >= Intensity)
            {
                if (East.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (East.FeatureBlob != null && savedFeature != East.FeatureBlob)
                    {
                        if (East.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = East.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = East.FeatureBlob;
                }
            }
            if (West != null && West.Intensity >= Intensity)
            {
                if (West.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (West.FeatureBlob != null && savedFeature != West.FeatureBlob)
                    {
                        if (West.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = West.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = West.FeatureBlob;
                }
            }
            if (NorthEast != null && NorthEast.Intensity >= Intensity)
            {
                if (NorthEast.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (NorthEast.FeatureBlob != null && savedFeature != NorthEast.FeatureBlob)
                    {
                        if (NorthEast.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = NorthEast.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = NorthEast.FeatureBlob;
                }
            }
            if (NorthWest != null && NorthWest.Intensity >= Intensity)
            {
                if (NorthWest.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (NorthWest.FeatureBlob != null && savedFeature != NorthWest.FeatureBlob)
                    {
                        if (NorthWest.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = NorthWest.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = NorthWest.FeatureBlob;
                }
            }
            if (SouthEast != null && SouthEast.Intensity >= Intensity)
            {
                if (SouthEast.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (SouthEast.FeatureBlob != null && savedFeature != SouthEast.FeatureBlob)
                    {
                        if (SouthEast.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = SouthEast.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = SouthEast.FeatureBlob;
                }
            }
            if (SouthWest != null && SouthWest.Intensity >= Intensity)
            {
                if (SouthWest.IsBackground)
                {
                    return(HigherNeighborResult.Background);
                }
                if (savedFeature != null)
                {
                    if (SouthWest.FeatureBlob != null && savedFeature != SouthWest.FeatureBlob)
                    {
                        if (SouthWest.FeatureBlob.PointList.Count > savedFeature.PointList.Count)
                        {
                            savedFeature = SouthWest.FeatureBlob;
                            featureCount++;
                        }
                        //return HigherNeighborResult.MultipleFeatures;
                    }
                }
                else
                {
                    savedFeature = SouthWest.FeatureBlob;
                }
            }

            if (savedFeature == null)
            {
                return(HigherNeighborResult.None);
            }

            feature = savedFeature;

            if (featureCount > 1)
            {
                return(HigherNeighborResult.MultipleFeatures);
            }

            return(HigherNeighborResult.OneFeature);
        }