示例#1
0
        private static object GetCellValue(int w, int h, int row, int col, IImageData image, Color c, Hashtable colorTable, ICollection <RcIndex> locations)
        {
            double dmin  = double.MaxValue;
            object val   = 0;
            bool   empty = true;

            // Search 8 neighbor cells for likely blended neighbors
            // (otherwise distant shapes might match better incorrectly)
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (i == j && j == 0)
                    {
                        continue;
                    }

                    if (row + i < 0 || row + i >= h)
                    {
                        continue;
                    }

                    if (col + j < 0 || col + j >= w)
                    {
                        continue;
                    }

                    Color nc = image.GetColor(row + i, col + j);
                    if (colorTable.ContainsKey(nc) == false)
                    {
                        continue;
                    }

                    double d = ((nc.R - c.R) * (nc.R - c.R)) + ((nc.G - c.G) * (nc.G - c.G)) + ((nc.B - c.B) * (nc.B - c.B));
                    if (d >= dmin)
                    {
                        continue;
                    }

                    val   = colorTable[nc];
                    dmin  = d;
                    empty = false;
                    image.SetColor(row, col, nc);
                }
            }

            if (empty)
            {
                locations.Add(new RcIndex(row, col));
            }

            return(val);
        }
示例#2
0
        private static object GetCellValue(int w, int h, int row, int col, IImageData image, Color c,
                                           Hashtable colorTable, ICollection<RcIndex> locations)
        {
            double dmin = double.MaxValue;
            object val = 0;
            bool empty = true;

            // Search 8 neighbor cells for likely blended neighbors
            // (otherwise distant shapes might match better incorrectly)
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (i == j && j == 0)
                    {
                        continue;
                    }
                    if (row + i < 0 || row + i >= h)
                    {
                        continue;
                    }
                    if (col + j < 0 || col + j >= w)
                    {
                        continue;
                    }
                    Color nc = image.GetColor(row + i, col + j);
                    if (colorTable.ContainsKey(nc) == false)
                    {
                        continue;
                    }
                    double d = ((nc.R - c.R) * (nc.R - c.R)) + ((nc.G - c.G) * (nc.G - c.G)) +
                               ((nc.B - c.B) * (nc.B - c.B));
                    if (d >= dmin)
                    {
                        continue;
                    }

                    val = colorTable[nc];
                    dmin = d;
                    empty = false;
                    image.SetColor(row, col, nc);
                }
            }
            if (empty)
            {
                locations.Add(new RcIndex(row, col));
            }
            return val;
        }