pyodide/benchmark/benchmarks/harris.py

30 lines
651 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# from: parakeet testbed
# setup: import numpy as np ; M, N = 512, 512 ; I = np.random.randn(M,N)
# run: harris(I)
2018-04-05 22:07:33 +00:00
2018-10-03 18:59:01 +00:00
# pythran export harris(float64[][])
2018-04-05 22:07:33 +00:00
def harris(I):
2018-10-03 18:59:01 +00:00
m, n = I.shape
dx = (I[1:, :] - I[:m - 1, :])[:, 1:]
dy = (I[:, 1:] - I[:, :n - 1])[1:, :]
2018-04-05 22:07:33 +00:00
2018-10-03 18:59:01 +00:00
#
# At each point we build a matrix
# of derivative products
# M =
# | A = dx^2 C = dx * dy |
# | C = dy * dx B = dy * dy |
#
# and the score at that point is:
# det(M) - k*trace(M)^2
#
A = dx * dx
B = dy * dy
C = dx * dy
tr = A + B
det = A * B - C * C
k = 0.05
return det - k * tr * tr