diff --git a/doc/examples/plot_orb_matching.py b/doc/examples/plot_orb_matching.py index 78409dd1..660aadae 100644 --- a/doc/examples/plot_orb_matching.py +++ b/doc/examples/plot_orb_matching.py @@ -1,37 +1,54 @@ import numpy as np from skimage import data from skimage import transform as tf -from skimage.feature import pairwise_hamming_distance, brief, match_binary_descriptors, corner_harris, corner_peaks, keypoints_orb, descriptor_orb +from skimage.feature import (pairwise_hamming_distance, + match_binary_descriptors, corner_harris, + corner_peaks, keypoints_orb, descriptor_orb) from skimage.color import rgb2gray from skimage import img_as_float import matplotlib.pyplot as plt +# Initializing parameters for transformation rotate = 0.5 translate = (-100, -200) scaling = (1.5, 1.5) -match_threshold = 0.25 -match_cross_check = True +# Creating a transformed image from the original Lena image by scaling and +# rotating it img_color = data.lena() -tform = tf.AffineTransform(scale = scaling, rotation=rotate, translation=translate) +tform = tf.AffineTransform(scale = scaling, rotation=rotate, + translation=translate) transformed_img_color = tf.warp(img_color, tform) img = rgb2gray(img_color) transformed_img = rgb2gray(transformed_img_color) +# Extracting oFAST keypoints and computing their rBRIEF descriptors keypoints1, orientations1, scales1 = keypoints_orb(img, n_keypoints=500) keypoints1.shape -descriptors1, keypoints1 = descriptor_orb(img, keypoints1, orientations1, scales1) +descriptors1, keypoints1 = descriptor_orb(img, keypoints1, orientations1, + scales1) keypoints1.shape descriptors1.shape -keypoints2, orientations2, scales2 = keypoints_orb(transformed_img, n_keypoints=500) +keypoints2, orientations2, scales2 = keypoints_orb(transformed_img, + n_keypoints=500) keypoints2.shape -descriptors2, keypoints2 = descriptor_orb(transformed_img, keypoints2, orientations2, scales2) +descriptors2, keypoints2 = descriptor_orb(transformed_img, keypoints2, + orientations2, scales2) keypoints2.shape descriptors2.shape +#Initializing parameters for Descriptor matching +match_threshold = 0.25 +match_cross_check = True + pairwise_hamming_distance(descriptors1, descriptors2) -matched_keypoints, mask1, mask2 = match_binary_descriptors(keypoints1, descriptors1, keypoints2, descriptors2, cross_check=match_cross_check, threshold=match_threshold) +matched_keypoints, mask1, mask2 = match_binary_descriptors(keypoints1, + descriptors1, + keypoints2, + descriptors2, + cross_check=match_cross_check, + threshold=match_threshold) matched_keypoints.shape @@ -41,7 +58,8 @@ dst = matched_keypoints[:, 1, :] src_scale = 10 * (scales1[mask1] + 1) ** 1.5 dst_scale = 10 * (scales2[mask2] + 1) ** 1.5 -img_combined = np.concatenate((img_as_float(img_color), img_as_float(transformed_img_color)), axis=1) +img_combined = np.concatenate((img_as_float(img_color), + img_as_float(transformed_img_color)), axis=1) offset = img.shape fig, ax = plt.subplots(nrows=1, ncols=1) diff --git a/skimage/feature/orb.py b/skimage/feature/orb.py index 7498f7e3..fb4a77ff 100644 --- a/skimage/feature/orb.py +++ b/skimage/feature/orb.py @@ -1,6 +1,7 @@ import numpy as np -from .util import _mask_border_keypoints, _prepare_grayscale_input_2D +from skimage.feature.util import (_mask_border_keypoints, + _prepare_grayscale_input_2D) from skimage.feature import (corner_fast, corner_orientations, corner_peaks, corner_harris)