Back to Browse

Descripteurs de Forme : SIFT (Scale Invariant Feature Transform) + Feature Matching

843 views
Apr 13, 2024
31:04

# -*- coding: utf-8 -*- # %% Matching using SIFT Descriptor import cv2 import matplotlib.pyplot as plt import numpy as np #from skimage import data from skimage import transform from skimage.feature import match_descriptors, plot_matches, SIFT plt.close('all') image_name = 'fge.jpeg' A_bgr = cv2.imread(image_name) A_rgb = cv2.cvtColor(A_bgr, cv2.COLOR_BGR2RGB); img1 = cv2.cvtColor(A_bgr, cv2.COLOR_BGR2GRAY) img2 = transform.rotate(img1, 45) tform = transform.AffineTransform(scale=(1.3, 1.1), rotation=0.5, translation=(0, -100)) img3 = transform.warp(img1, tform) desc = SIFT() desc.detect_and_extract(img1) keypoints1 = desc.keypoints; descriptors1 = desc.descriptors desc.detect_and_extract(img2) keypoints2 = desc.keypoints; descriptors2 = desc.descriptors desc.detect_and_extract(img3) keypoints3 = desc.keypoints; descriptors3 = desc.descriptors matches12 = match_descriptors(descriptors1, descriptors2, max_ratio=0.6, cross_check=True) matches13 = match_descriptors(descriptors1, descriptors3, max_ratio=0.6, cross_check=True) plt.figure(4) # Features matching vizualisation fig, ax = plt.subplots(2,2) #plt.gray() plot_matches(ax[0, 0], img1, img2, keypoints1, keypoints2, matches12);ax[0, 0].axis('off') ax[0, 0].set_title("Original Image vs. Flipped Image\n" "(all keypoints and matches)") plot_matches(ax[1, 0], img1, img3, keypoints1, keypoints3, matches13); ax[1, 0].axis('off') ax[1, 0].set_title( "Original Image vs. Transformed Image\n" "(all keypoints and matches)") SUB1,_= np.shape(matches12); SUB1=SUB1//10 ; SUB2,_= np.shape(matches13); SUB2=SUB2//10 plot_matches(ax[0, 1], img1, img2, keypoints1, keypoints2, matches12[::SUB1], only_matches=True); ax[0, 1].axis('off') ax[0, 1].set_title("Original Image vs. Flipped Image\n" "(10 percents subset of matches for visibility)") plot_matches(ax[1, 1], img1, img3, keypoints1, keypoints3, matches13[::SUB2], only_matches=True);ax[1, 1].axis('off') ax[1, 1].set_title("Original Image vs. Transformed Image\n" "(10 percents subset of matches for visibility)") # #plt.tight_layout()

Download

0 formats

No download links available.

Descripteurs de Forme : SIFT (Scale Invariant Feature Transform) + Feature Matching | NatokHD