Haar-like filters consist of adjacent rectangular regions used to detect visual features like edges or lines. A crucial aspect of their use is the speed with which their response can be calculated, regardless of the filter size. This efficiency is achieved by using an Integral Image representation.
The Integral Image I(x,y) stores the sum of all pixel intensities in the original image that are above and to the left of position (x,y). Given the Integral Image, the sum of intensities within any rectangular region defined by top-left corner (x0,y0) and bottom-right corner (x1,y1) can be calculated with just four lookups:
Sum=I(x1,y1)+I(x0−1,y0−1)−I(x1,y0−1)−I(x0−1,y1)
Consider a 2-rectangle edge feature, defined by a Positive Region RP and an adjacent Negative Region RN. The filter's response is the difference between the sum of intensities in the positive region and the sum in the negative region:
Response=Sum(RP)−Sum(RN)
Your task is to compute the response of a vertical 2-rectangle Haar-like filter, given the Integral Image I and the coordinates defining the two regions.
I = [[1, 2, 3, 4],
[3, 6, 9, 12],
[4, 8, 12, 16],
[5, 10, 15, 20]]
rp = [0, 0, 1, 0] # Positive region: rows 0-1, col 0
rn = [2, 0, 3, 0] # Negative region: rows 2-3, col 01
Calculate Sum(RP) for region [0,0] to [1,0]:
Calculate Sum(RN) for region [2,0] to [3,0]:
Response = 3−2=1