Question: Problem 5 . 2 : Naive Matching [ 8 points ] this, namely, for each corner in image 1 , find the best match from

Problem 5.2: Naive Matching [8 points] this, namely, for each corner in image1, find the best match from the detected corners in image2(or, if the NCC match score is too low, then return no match for that point).
Write a function and call it as below. Examine your results for 20 detected corners in each image.
Note: Your matches may not be perfect.
```
def naive_matching(img1, img2, corners1, corners2, R, NCCth):
"""
Compute NCC given two windows.
Args:
img1: Image 1.
img2: Image 2.
corners1: Corners in image 1(nx2)
corners2: Corners in image 2(nx2)
R: NCC matching radius
NCCth: NCC matching score threshold
Returns:
matching: NCC matching returns a list of tuple (c1, c2),
c1 is the 1x2 corner location in image 1,
c2 is the 1x2 corner location in image 2.
"""
### YOUR CODE HERE
raise NotImplementedError("Delete this line once you implement the function")
### END YOUR CODE
return matching
``````
# Detect corners on warrior and matrix sets
# You are free to modify the parameters
n_corners =20
smooth_std =1
window_size =17
# Read images and detect corners on the images
imgs_mat =[]
crns_mat =[]
imgs_war =[]
crns_war =[]
for i in range(2):
img_mat = io.imread('./p6/matrix/matrix'+ str(i)+'.png')
imgs_mat.append(rgb2gray(img_mat))
img_war = io.imread('./p6/warrior/warrior'+ str(i)+'.png')
imgs_war.append(rgb2gray(img_war))
# Match corners
crnsmatf=open('./p6/matrix/crns_mat.pkl','rb')
crns_mat=pickle.load(crnsmatf)
crnswarf=open('./p6/warrior/crns_war.pkl','rb')
crns_war=pickle.load(crnswarf)
R =31
NCCth =2400
matching_mat = naive_matching(imgs_mat[0]/255, imgs_mat[1]/255, crns_mat[0], crns_mat[1], R, NCCth)
matching_war = naive_matching(imgs_war[0]/255, imgs_war[1]/255, crns_war[0], crns_war[1], R, NCCth)
]:
# Plot matching result
def show_matching_result(img1, img2, matching):
fig = plt.figure(figsize=(8,8))
plt.imshow(np.hstack((img1, img2)), cmap='gray') # two dino images are of different sizes, resize one before use
for p1, p2 in matching:
plt.scatter(p1[0], p1[1], s=35, edgecolors='r', facecolors='none')
plt.scatter(p2[0]+ img1.shape[1], p2[1], s=35, edgecolors='r', facecolors='none')
plt.plot([p1[0], p2[0]+ img1.shape[1]],[p1[1], p2[1]])
#plt.savefig('matching.png')
plt.show()
print("Number of Corners:", n_corners)
show_matching_result(imgs_mat[0], imgs_mat[1], matching_mat)
show_matching_result(imgs_war[0], imgs_war[1], matching_war)
```
Problem 5 . 2 : Naive Matching [ 8 points ] this,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!