mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 07:43:56 +08:00
Add convenience function for plotting matches
This commit is contained in:
+13
-40
@@ -16,62 +16,35 @@ import numpy as np
|
||||
from skimage import data
|
||||
from skimage import transform as tf
|
||||
from skimage.feature import (match_descriptors, corner_harris,
|
||||
corner_peaks, ORB)
|
||||
corner_peaks, ORB, plot_matches)
|
||||
from skimage.color import rgb2gray
|
||||
from skimage import img_as_float
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
img1_color = data.lena()
|
||||
img2_color = tf.rotate(img1_color, 180)
|
||||
img1 = rgb2gray(data.lena())
|
||||
img2 = tf.rotate(img1, 180)
|
||||
tform = tf.AffineTransform(scale=(1.3, 1.1), rotation=0.5,
|
||||
translation=(0, -200))
|
||||
img3_color = tf.warp(img1_color, tform)
|
||||
img1 = rgb2gray(img1_color)
|
||||
img2 = rgb2gray(img2_color)
|
||||
img3 = rgb2gray(img3_color)
|
||||
img3 = tf.warp(img1, tform)
|
||||
|
||||
descriptor_extractor = ORB(n_keypoints=200)
|
||||
keypoints1, descriptors1 = descriptor_extractor.detect_and_extract(img1)
|
||||
keypoints2, descriptors2 = descriptor_extractor.detect_and_extract(img2)
|
||||
keypoints3, descriptors3 = descriptor_extractor.detect_and_extract(img3)
|
||||
|
||||
idxs1, idxs2 = match_descriptors(descriptors1, descriptors2, cross_check=True)
|
||||
src12 = keypoints1[idxs1]
|
||||
dst12 = keypoints2[idxs2]
|
||||
|
||||
idxs1, idxs3 = match_descriptors(descriptors1, descriptors3, cross_check=True)
|
||||
src13 = keypoints1[idxs1]
|
||||
dst13 = keypoints3[idxs3]
|
||||
|
||||
img12 = np.concatenate((img_as_float(img1_color),
|
||||
img_as_float(img2_color)), axis=1)
|
||||
img13 = np.concatenate((img_as_float(img1_color),
|
||||
img_as_float(img3_color)), axis=1)
|
||||
|
||||
imgs = (img12, img13)
|
||||
srcs = (src12, src13)
|
||||
dsts = (dst12, dst13)
|
||||
|
||||
offset = img1.shape
|
||||
|
||||
fig, ax = plt.subplots(nrows=2, ncols=1)
|
||||
|
||||
for i in range(2):
|
||||
plt.gray()
|
||||
|
||||
ax[i].imshow(imgs[i], interpolation='nearest')
|
||||
ax[i].axis('off')
|
||||
ax[i].axis((0, 2 * offset[1], offset[0], 0))
|
||||
idxs1, idxs2 = match_descriptors(descriptors1, descriptors2, cross_check=True)
|
||||
plot_matches(ax[0], img1, img2, keypoints1, keypoints2,
|
||||
idxs1, idxs2)
|
||||
ax[0].axis('off')
|
||||
|
||||
src = srcs[i]
|
||||
dst = dsts[i]
|
||||
|
||||
for m in range(len(src)):
|
||||
color = np.random.rand(3, 1)
|
||||
ax[i].plot((src[m, 1], dst[m, 1] + offset[1]), (src[m, 0], dst[m, 0]),
|
||||
'-', color=color)
|
||||
ax[i].scatter(src[m, 1], src[m, 0], facecolors='none', edgecolors=color)
|
||||
ax[i].scatter(dst[m, 1] + offset[1], dst[m, 0], facecolors='none',
|
||||
edgecolors=color)
|
||||
idxs1, idxs3 = match_descriptors(descriptors1, descriptors3, cross_check=True)
|
||||
plot_matches(ax[1], img1, img3, keypoints1, keypoints3,
|
||||
idxs1, idxs3)
|
||||
ax[1].axis('off')
|
||||
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user