Answered step by step
Verified Expert Solution
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, maximumfilter
def derivativefilters:
Create derivative filters for x and y direction
Returns:
fx: derivative filter in x direction
fy: derivative filter in y direction
fx nparray
fy fxtranspose
return fx fy
def gaussdsigma fsize:
Create a D Gaussian filter
Args:
sigma: width of the Gaussian filter
fsize: h w dimensions of the filter
Returns:
normalized Gaussian filter as h w nparray
m n fsize
x nparangem m
y nparangen n
xx yy npmeshgridx y sparseTrue
g npexpxx yy sigma
return g npsumg
def computehessianimg 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:
Ixx: h w nparray of nd derivatives in x direction
Iyy: h w nparray of nd derivatives in y direction
Ixy: h w nparray of nd derivatives in xy direction
#
# You code here
#
def computecriterionIxx Iyy Ixy sigma:
Compute criterion function
Args:
Ixx: h w nparray of nd derivatives in x direction
Iyy: h w nparray of nd derivatives in y direction
Ixy: h w nparray of nd derivatives in xy direction
sigma: scaling factor
Returns:
criterion: h w nparray of scaled determinant of Hessian matrix
#
# You code here
#
def nonmaxsuppressioncriterion threshold:
Apply nonmaximum suppression to criterion values
and return Hessian interest points
Args:
criterion: h w nparray of criterion function values
threshold: criterion threshold
Returns:
rows: n nparray with ypositions of interest points
cols: n nparray with xpositions of interest points
#
# You code here
#
# Set paramters and load the image
sigma
threshold e
color, gray loadimgdataappng
# Generate filters and compute Hessian
fx fy derivativefilters
gauss gaussdsigma
Ixx Iyy Ixy computehessiangray gauss, fx fy
# Show components of Hessian matrix
pltfigure
pltsubplot
plotheatmapIxxIxx
pltsubplot
plotheatmapIyyIyy
pltsubplot
plotheatmapIxyIxy
# Compute and show Hessian criterion
criterion computecriterionIxx Iyy Ixy sigma
pltsubplot
plotheatmapcriterion "Determinant of Hessian"
# Show all interest points where criterion is greater than threshold
rows, cols npnonzerocriterion threshold
showpointscolor rows, cols
# Apply nonmaximum suppression and show remaining interest points
rows, cols nonmaxsuppressioncriterion threshold
showpointscolor rows, cols
pltshow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started