Created
September 30, 2011 18:09
-
-
Save kscottz/1254539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def integral_image(img): | |
gnp = img.toGray().getNumpy()[:,:,0] | |
retVal = np.zeros(gnp.shape); | |
for i in range(gnp.shape[0]):#width | |
for j in range(gnp.shape[1]): #height | |
if( i > 0 and j > 0): | |
retVal[i,j] = retVal[i,j-1]; #add the entry above us | |
retVal[i,j] += retVal[i-1,j] #add everything to our left | |
retVal[i,j] -= retVal[i-1,j-1] #subtract off everything we count twice | |
retVal[i,j] += gnp[i,j] #our value | |
elif( i == 0 and j > 0): #add our value to the value above | |
retVal[i,j]=retVal[i,j-1]+gnp[i,j] | |
elif( i > 0 and j == 0 ): # add our value to the left | |
retVal[i,j]=retVal[i-1,j]+gnp[i,j] | |
else: # start | |
retVal[i,j] = gnp[i,j] | |
return retVal; | |
def integral_image_slow(img): | |
gnp = img.toGray().getNumpy()[:,:,0] | |
retVal = np.zeros(gnp.shape); | |
for i in range(gnp.shape[0]): | |
for j in range(gnp.shape[1]): | |
retVal[i,j] = np.sum(gnp[0:i,0:j]) | |
return retVal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment