Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code outline and main code ( in attached image ) made by me is given complete the code Full compete it should work test it
Code outline and main code in attached image made by me is given complete the code Full compete it should work test it with any two pics
Code Outline:
import numpy as np
import matplotlib.pyplot as plt
def loadptsfeaturespath:
Load interest points and SIFT features.
Args:
path: path to the file ptsfeats.npz
Returns:
pts: coordinate points for two images;
an array of numpy arrays NN
feats: SIFT descriptors for two images;
an array of numpy arrays NN
#
# Your code here
#
pts npempty npempty
feats npempty npempty
return pts feats
def minnumpairs:
return nprandom.randint
def pickupsamplespts pts:
Randomly select k corresponding point pairs.
Note that here we assume that pts and pts have
been already aligned: ptsk corresponds to ptsk
This function makes use of minnumpairs
Args:
pts and pts: point coordinates from Image and Image
Returns:
ptssub and ptssub: Nmin randomly selected points
from pts and pts
#
#Your code here
#
return None, Non
def computehomographypts pts:
Construct homography matrix and solve it by SVD
Args:
pts: the coordinates of interest points in img array N
pts: the coordinates of interest points in img array M
Returns:
H: homography matrix as array
#
# Your code here
#
return npempty
def transformptspts H:
Transform pst through the homography matrix to compare pts to find inliners
Args:
pts: interest points in img array N
H: homography matrix as array
Returns:
transformed points, array N
#
# Your code here
#
return npempty
def countinliersH pts pts threshold:
Count inliers
Tips: We provide the default threshold value, but you're free to test other values
Args:
H: homography matrix as array
pts: interest points in img array N
pts: interest points in img array N
threshold: scale down threshold
Returns:
number of inliers
return npempty
def ransacitersw dminnumpairs z:
Computes the required number of iterations for RANSAC.
Args:
w: probability that any given correspondence is valid
d: minimum number of pairs
z: total probability of success after all iterations
Returns:
minimum number of required iterations
return npempty
def ransacpts pts:
RANSAC algorithm
Args:
pts: matched points in img array N
pts: matched points in img array N
Returns:
best homography observed during RANSAC, array
#
# Your code here
#
bestH npempty
return bestH
def findmatchesfeats feats rT:
Find pairs of corresponding interest points with distance comparsion
Tips: We provide the default ratio value, but you're free to test other values
Args:
feats: SIFT descriptors of interest points in img array N
feats: SIFT descriptors of interest points in img array M
rT: Ratio of similar distances
Returns:
idx: list of indices of matching points in img
idx: list of indices of matching points in img
idx
idx
#
# Your code here
#
return idx idx
def finalhomographypts pts feats feats:
reestimate the homography based on all inliers
Args:
pts: the coordinates of interest points in img array N
pts: the coordinates of interest points in img array M
feats: SIFT descriptors of interest points in img array N
feats: SIFT descriptors of interest points in img array M
Returns:
ransacreturn: refitted homography matrix from ransac fucation, array
idxs: list of matched points in image
idxs: list of matched points in image
#
# Your code here
#
idxs idxs
ransacreturn npempty
return ransacreturn, idxs idxsptsarray,
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