Exemplo n.º 1
0
        /// <summary>
        /// Return the segmentation-derived mask for the character.
        /// This may optionally be grown by some pixels.
        /// </summary>
        public override void GetMask(out Rect r, ref Bytearray outmask, int index, int grow)
        {
            r = boxes.At1d(index).Grow(grow);
            r.Intersect(new Rect(0, 0, labels.Dim(0), labels.Dim(1)));
            if (fullheight)
            {
                r.y0 = 0;
                r.y1 = labels.Dim(1);
            }
            int      x = r.x0, y = r.y0, w = r.Width(), h = r.Height();
            Intarray segs = segments.At1d(index);

            outmask.Resize(w, h);
            outmask.Fill(0);
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int label = labels[x + i, y + j];
                    if (NarrayUtil.first_index_of(segs, label) >= 0)
                    {
                        outmask[i, j] = (byte)255;
                    }
                }
            }
            if (grow > 0)
            {
                Morph.binary_dilate_circle(outmask, grow);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a mask at a given location
        /// </summary>
        public override void GetMaskAt(ref Bytearray mask, int index, Rect b)
        {
            if (!(b.x0 > -1000 && b.x1 < 10000 && b.y0 > -1000 && b.y1 < 10000))
            {
                throw new Exception("CHECK: (b.Left > -1000 && b.Right < 10000 && b.Top > -1000 && b.Bottom < 10000)");
            }
            mask.Resize(b.Width(), b.Height());
            mask.Fill(0);
            Intarray segs = segments.At1d(index);
            int      w = b.Width(), h = b.Height();

            for (int i = 0; i < w; i++)
            {
                int x = b.x0 + i;
                unchecked
                {
                    if ((uint)x >= labels.Dim(0))
                    {
                        continue;
                    }
                }
                for (int j = 0; j < h; j++)
                {
                    int y = b.y0 + j;
                    unchecked
                    {
                        if (((uint)y) >= labels.Dim(1))
                        {
                            continue;
                        }
                    }
                    int label = labels[b.x0 + i, b.y0 + j];
                    if (NarrayUtil.first_index_of(segs, label) >= 0)
                    {
                        mask[i, j] = (byte)255;
                    }
                }
            }
        }