def color_gmagnitude(img, sigma=None, norm=True, enhance=False):
"""
"""
if sigma is not None:
img = gaussian(img, sigma=sigma, multichannel=True)
dx = np.dstack([sobel_h(img[..., i]) for i in range(img.shape[-1])])
dy = np.dstack([sobel_v(img[..., i]) for i in range(img.shape[-1])])
Jx = np.sum(dx**2, axis=-1)
Jy = np.sum(dy**2, axis=-1)
Jxy = np.sum(dx * dy, axis=-1)
D = np.sqrt(np.abs(Jx**2 - 2 * Jx * Jy + Jy**2 + 4 * Jxy**2))
e1 = (Jx + Jy + D) / 2. # First eigenvalue
magnitude = np.sqrt(e1)
if norm:
magnitude /= magnitude.max()
if enhance:
magnitude = 1 - np.exp(-magnitude**2 / magnitude.mean())
return magnitude.astype(np.float32)
评论列表
文章目录