Exemplo n.º 1
0
        public List <Int16DoubleWithValue> FindMaxima()
        {
            List <Int16DoubleWithValue> list = FindLocalMaxima();

            list.Sort();
            FlagMap2d flag = new FlagMap2d(bmp.width, bmp.height, 0);
            List <Int16DoubleWithValue> r    = new List <Int16DoubleWithValue>();
            List <Int16Double>          temp = new List <Int16Double>();

            for (int i = 0; i < list.Count; i++)
            {
                if (flag.GetFlagOn(list[i].X, list[i].Y) == UNPROCESSED)
                {
                    bool ret = FloodFill(list[i].X, list[i].Y, temp, flag);
                    if (ret)
                    {
                        r.Add(list[i]);

                        MarkAll(temp, PROCESSED, flag);
                    }
                    else
                    {
                        MarkAll(temp, UNPROCESSED, flag);
                        flag.SetFlagOn(list[i].X, list[i].Y, PROCESSED);
                    }
                    temp.Clear();
                }
            }
            return(r);
        }
Exemplo n.º 2
0
 private void MarkAll(List <Int16Double> ret, byte v, FlagMap2d flag)
 {
     for (int i = 0; i < ret.Count; i++)
     {
         flag.SetFlagOn(ret[i].X, ret[i].Y, v);
     }
 }
Exemplo n.º 3
0
        private bool FloodFill(int x, int y, List <Int16Double> ret, FlagMap2d flag)
        {
            ret.Clear();
            Queue <Int16Double> queue = new Queue <Int16Double>();

            ret.Add(new Int16Double(x, y));
            float pvalue = bmp.GetPixel(x, y);

            flag.SetFlagOn(x, y, VISITED);
            queue.Enqueue(new Int16Double(x, y));
            while (queue.Count != 0)
            {
                Int16Double p = queue.Dequeue();
                for (int i = 0; i < 8; i++)
                {
                    int tx = p.X + Delta[i].X;
                    int ty = p.Y + Delta[i].Y;
                    if (InRange(tx, ty))
                    {
                        byte f = flag.GetFlagOn(tx, ty);
                        if (f == PROCESSED)
                        {
                            return(false);
                        }
                        else
                        {
                            bool minum = false;
                            if (IncludePredicate(tx, ty, pvalue, ref minum) && f == UNPROCESSED)
                            {
                                if (minum)
                                {
                                    return(false);
                                }
                                Int16Double t = new Int16Double(tx, ty);
                                queue.Enqueue(t);
                                flag.SetFlagOn(tx, ty, VISITED);
                                ret.Add(t);
                            }
                        }
                    }
                }
            }
            return(true);
        }