Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem we will take a look at interest point detection Please complete the code according to the instruction given in above code skeleton.

In this problem we will take a look at interest point detection
Please complete the code according to the instruction given in above code skeleton. DDONT CHANGE ANYTHING
CODE SKELETON:
import numpy as np
from scipy.ndimage import convolve, maximum_filter
def derivative_filters():
""" Create derivative filters for x and y direction
Returns:
fx: derivative filter in x direction
fy: derivative filter in y direction
"""
fx = np.array([[0.5,0,-0.5]])
fy = fx.transpose()
return fx, fy
def gauss_2d(sigma, fsize):
""" Create a 2D Gaussian filter
Args:
sigma: width of the Gaussian filter
fsize: (h, w) dimensions of the filter
Returns:
*normalized* Gaussian filter as (h, w) np.array
"""
m, n = fsize
x = np.arange(-m /2+0.5, m /2)
y = np.arange(-n /2+0.5, n /2)
xx, yy = np.meshgrid(x, y, sparse=True)
g = np.exp(-(xx **2+ yy **2)/(2* sigma **2))
return g / np.sum(g)
def compute_hessian(img, gauss, fx, fy):
""" Compute elements of the Hessian matrix
Args:
img: numpy array with the image
gauss: Gaussian filter
fx: derivative filter in x direction
fy: derivative filter in y direction
Returns:
I_xx: (h, w) np.array of 2nd derivatives in x direction
I_yy: (h, w) np.array of 2nd derivatives in y direction
I_xy: (h, w) np.array of 2nd derivatives in x-y direction
"""
#
# You code here
#
def compute_criterion(I_xx, I_yy, I_xy, sigma):
""" Compute criterion function
Args:
I_xx: (h, w) np.array of 2nd derivatives in x direction
I_yy: (h, w) np.array of 2nd derivatives in y direction
I_xy: (h, w) np.array of 2nd derivatives in x-y direction
sigma: scaling factor
Returns:
criterion: (h, w) np.array of scaled determinant of Hessian matrix
"""
#
# You code here
#
def non_max_suppression(criterion, threshold):
""" Apply non-maximum suppression to criterion values
and return Hessian interest points
Args:
criterion: (h, w) np.array of criterion function values
threshold: criterion threshold
Returns:
rows: (n,) np.array with y-positions of interest points
cols: (n,) np.array with x-positions of interest points
"""
#
# You code here
#
# Set paramters and load the image
sigma =5
threshold =1.5e-3
color, gray = load_img("data/a3p2.png")
# Generate filters and compute Hessian
fx, fy = derivative_filters()
gauss = gauss_2d(sigma,(25,25))
I_xx, I_yy, I_xy = compute_hessian(gray, gauss, fx, fy)
# Show components of Hessian matrix
plt.figure()
plt.subplot(1,4,1)
plot_heatmap(I_xx,"I_xx")
plt.subplot(1,4,2)
plot_heatmap(I_yy,"I_yy")
plt.subplot(1,4,3)
plot_heatmap(I_xy,"I_xy")
# Compute and show Hessian criterion
criterion = compute_criterion(I_xx, I_yy, I_xy, sigma)
plt.subplot(1,4,4)
plot_heatmap(criterion, "Determinant of Hessian")
# Show all interest points where criterion is greater than threshold
rows, cols = np.nonzero(criterion > threshold)
show_points(color, rows, cols)
# Apply non-maximum suppression and show remaining interest points
rows, cols = non_max_suppression(criterion, threshold)
show_points(color, rows, cols)
plt.show()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions