GetRectangleSum() public method

Calculate sum of pixels in the specified rectangle.

The method calculates sum of pixels in square rectangle with odd width and height. In the case if it is required to calculate sum of 3x3 rectangle, then it is required to specify its center and radius equal to 1.

public GetRectangleSum ( int x, int y, int radius ) : uint
x int X coordinate of central point of the rectangle.
y int Y coordinate of central point of the rectangle.
radius int Radius of the rectangle.
return uint
        private double haarX(int row, int column, int size)
        {
            double a = integral.GetRectangleSum(column, row - size / 2,
                                                column + size / 2 - 1, row - size / 2 + size - 1);

            double b = integral.GetRectangleSum(column - size / 2, row - size / 2,
                                                column - size / 2 + size / 2 - 1, row - size / 2 + size - 1);

            return((a - b) / 255.0);
        }
Ejemplo n.º 2
0
        private float haarX(int y, int x, int size)
        {
            int hsize = size / 2;
            int y1 = y - hsize;
            int y2 = y1 + size - 1;

            float a = integral.GetRectangleSum(x, y1, x + hsize - 1, y2);
            float b = integral.GetRectangleSum(x - hsize, y1, x - 1, y2);

            return (a - b) / 255f;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Computes the filter for the specified integral image.
        /// </summary>
        ///
        /// <param name="image">The integral image.</param>
        ///
        public void Compute(IntegralImage image)
        {
            int   b = (Size - 1) / 2 + 1;
            int   c = Size / 3;
            int   w = Size;
            float inv = 1f / (w * w);
            float Dxx, Dyy, Dxy;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    // Get the image coordinates
                    int i = y * Step;
                    int j = x * Step;

                    // Compute response components
                    Dxx = ((int)image.GetRectangleSum(j - b, i - c + 1, j - b + w - 1, i - c + 2 * c - 1)
                           - (int)image.GetRectangleSum(j - c / 2, i - c + 1, j - c / 2 + c - 1, i - c + 2 * c - 1) * 3);

                    Dyy = ((int)image.GetRectangleSum(j - c + 1, i - b, j - c + 2 * c - 1, i - b + w - 1)
                           - (int)image.GetRectangleSum(j - c + 1, i - c / 2, j - c + 2 * c - 1, i - c / 2 + c - 1) * 3);

                    Dxy = ((int)image.GetRectangleSum(j + 1, i - c, j + c, i - 1)
                           + (int)image.GetRectangleSum(j - c, i + 1, j - 1, i + c)
                           - (int)image.GetRectangleSum(j - c, i - c, j - 1, i - 1)
                           - (int)image.GetRectangleSum(j + 1, i + 1, j + c, i + c));

                    // Normalize the filter responses with respect to their size
                    Dxx *= inv / 255f;
                    Dyy *= inv / 255f;
                    Dxy *= inv / 255f;

                    // Get the determinant of Hessian response & Laplacian sign
                    Responses[y, x] = (Dxx * Dyy) - (0.9f * 0.9f * Dxy * Dxy);
                    Laplacian[y, x] = (Dxx + Dyy) >= 0 ? 1 : 0;
                }
            }
        }
 private static float sum(IntegralImage img, int row, int col, int rows, int cols)
 {
     return(img.GetRectangleSum(col, row, col + cols - 1, row + rows - 1) / 255f);
 }