Skip to content

Instantly share code, notes, and snippets.

@LeeKamentsky
Created November 25, 2015 15:50
Show Gist options
  • Save LeeKamentsky/cff0b04d91ecda904eba to your computer and use it in GitHub Desktop.
Save LeeKamentsky/cff0b04d91ecda904eba to your computer and use it in GitHub Desktop.
Kirsch
def rotate(direction, index):
return direction[-index:] + direction[:-index]
def make_kernel(convolution_mask):
k = list(convolution_mask)
k.insert(4, 0)
return np.array(k).reshape(3, 3)
def kirsch(img):
convolution_mask = [5, -3, -3, -3, -3, -3, 5, 5]
output = np.zeros(img.shape)
for _ in range(8):
c = convolve(img, make_kernel(convolution_mask))
output = np.maximum(output, c)
convolution_mask = rotate(convolution_mask, 1)
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment