Skip to content

Instantly share code, notes, and snippets.

@vivekseth
Created January 4, 2017 17:07
Show Gist options
  • Save vivekseth/76744965c7b780291d21dcdd81339549 to your computer and use it in GitHub Desktop.
Save vivekseth/76744965c7b780291d21dcdd81339549 to your computer and use it in GitHub Desktop.
def magnitude(image, pos):
x, y = pos
return np.mean(image[x, y])
def isPeak(image, pos, threshold):
x, y = pos
mag = magnitude(image, pos)
for i in range(x-1, x+1):
for j in range(y-1, y+1):
if i == x and j == y:
continue
elif (magnitude(image, (i, j)) / mag) > (1 - threshold) :
return False
return True
def feature_detector(image, threshold):
features = []
for i in range(1, image.shape[0]-1):
for j in range(1, image.shape[1]-1):
if isPeak(image, (i, j), threshold):
features.append((i, j))
return features
image = cv2.imread('./small.tiff')
features = feature_detector(image, 0.1)
for (y, x) in features:
image = cv2.circle(image, (x, y), 2, (0, 0, 0), 0)
cv2.imshow('features', image)
k = cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment