-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement summed area table integration trick #5
Comments
Do you just want a class that takes an array, computes the summed area table, and has a function sum(x1,y1,x2,y2) that returns the sum with those opposite corners? |
@ctralie might have a better idea of how to go about doing this as he introduced me to the trick. I imagine the implementation would replace this code: Lines 110 to 120 in 0978c7d
Where it is object oriented, a function, or inlined is up to the implementer. Hopefully whatever is easiest. |
Well, if it helps, here's a quick class that implements the basic algorithm. class SummedAreaTable:
def __init__(self,img):
self.img = img
self.table = np.zeros_like(self.img)
rows,cols = self.img.shape
# First row
self.table[0] = np.cumsum(self.img[0])
# First column
self.table[1:,0] = np.cumsum(self.img[:,0])[1:]
for row in range(1,rows):
for col in range(1,cols):
self.table[row,col] = self.img[row,col] + self.table[row,col-1] + self.table[row-1,col] - self.table[row-1,col-1]
def tablesum(self,x1,y1,x2,y2):
return self.table[x2,y2] + self.table[x1,y1] - self.table[x1,y2] - self.table[x2,y1] |
Thanks Rann. I'm just going to copy in something inline like what I've done here: |
See https://en.wikipedia.org/wiki/Summed-area_table
The text was updated successfully, but these errors were encountered: