I tried to extract features with SIFT of OpenCV

What is SIFT?

SIFT algorithm

[Detection of feature points]

1-1. Search for candidate points that will be feature points 1-2. Narrowing down candidate points

[Description of features]

2-1. Detect the gradient of each feature point 2-2. Gradient direction histogram calculation of each feature point

1-1. Search for candidate points that will be feature points

A feature point is a point that takes an extreme value in a difference image (DoG image) in the scale direction. To summarize briefly, a dimension called ** scale ** is added to a two-dimensional (x, y) image to make it three-dimensional. As for how to determine the scale, consider (x, y, σ) in which the image (x, y) is ** smoothed ** by a certain amount σ. Use ** Gaussian filter ** for smoothing. Use this data to identify potential feature points. A large amount of change means a large amount of information.

1-2. Narrowing down candidate points

Since the output value of the DoG image is a function that uses (x, y, σ) as a variable, approximate it around the feature points and recalculate the point that takes the extreme value using the derivative of the approximate expression. That's it. Excludes points on the edge. Excludes those with a small DoG output value.

2-1. Detect the gradient of each feature point

--Create a luminance gradient histogram around the feature points --Direction / strength calculation is almost the same as HoG --36 directions

point Intensity is weighted with a Gaussian filter on the feature point scale. ⇒Become resistant to scale changes.

--In the obtained histogram, the direction in which the intensity exceeds 80% of the maximum value is defined as the direction of this feature point.

2-2. Gradient direction histogram calculation of each feature point

--Create a luminance gradient histogram again with the direction of the feature points as the reference direction (strong against rotation). --Directions are 8 directions (45 degrees each) --4x4x8 = 128-dimensional features --Normalize (this makes it more resistant to lighting changes)

SIFT code

This is a sample code.


import cv2
import numpy as np

img = cv2.imread('dog.jpg')
sift = cv2.xfeatures2d.SIFT_create()
keypoints, descriptors = sift.detectAndCompute(img, None)
img_sift = cv2.drawKeypoints(img, keypoints, None, flags=4)
cv2.imwrite("sift_img.jpg ",img_sift)

--image: Input image --keypoints: Keypoints obtained from the input image --flags: Identification setting of drawing function

Input image dog.jpeg

Output image

sift_img.jpg

References

-About Sift features

-Introduction of SIFT (Scale-Invariant Feature Transfrom)

Recommended Posts

I tried to extract features with SIFT of OpenCV
I tried to detect motion quickly with OpenCV
I tried to automatically extract the movements of PES players with software
[OpenCV / Python] I tried image analysis of cells with OpenCV
I tried "morphology conversion" of images with Python + OpenCV
I tried trimming efficiently with OpenCV
I tried using GrabCut of OpenCV
I tried face recognition with OpenCV
I tried "gamma correction" of the image with Python + OpenCV
I tried to find the average of the sequence with TensorFlow
I tried to implement ListNet of rank learning with Chainer
Try to extract the features of the sensor data with CNN
I want to detect objects with OpenCV
I tried to implement Autoencoder with TensorFlow
I tried to automate the watering of the planter with Raspberry Pi
I tried to visualize AutoEncoder with TensorFlow
I tried to get started with Hy
I tried to create a list of prime numbers with python
I tried non-photorealistic rendering with Python + opencv
I tried to process the image in "sketch style" with OpenCV
I tried to fix "I tried stochastic simulation of bingo game with Python"
I tried to implement CVAE with PyTorch
I tried to process the image in "pencil style" with OpenCV
I tried to expand the size of the logical volume with LVM
I want to check the position of my face with OpenCV!
I tried to solve TSP with QAOA
I tried to improve the efficiency of daily work with Python
I tried to automatically collect images of Kanna Hashimoto with Python! !!
I tried to make an image similarity function with Python + OpenCV
I tried to make a mechanism of exclusive control with Go
I tried to extract characters from subtitles (OpenCV: Google Cloud Vision API)
I tried to get the authentication code of Qiita API with Python.
I tried to extract and illustrate the stage of the story using COTOHA
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I tried to streamline the standard role of new employees with Python
I tried to visualize the text of the novel "Weathering with You" with WordCloud
I tried to get the movie information of TMDb API with Python
I tried to visualize all decision trees of random forest with SVG
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried handwriting recognition of runes with scikit-learn
I tried to predict next year with AI
I tried "smoothing" the image with Python + OpenCV
I tried hundreds of millions of SQLite with python
I tried to detect Mario with pytorch + yolov3
I tried to implement reading Dataset with PyTorch
I tried to use lightGBM, xgboost with Boruta
I tried image recognition of CIFAR-10 with Keras-Learning-
I tried to learn logical operations with TF Learn
I tried to move GAN (mnist) with keras
I tried "differentiating" the image with Python + OpenCV
I tried image recognition of CIFAR-10 with Keras-Image recognition-
I tried to notify slack of Redmine update
I tried to save the data with discord
I tried to find 100 million digits of pi
I tried to integrate with Keras in TFv1.1
I tried Flask with Remote-Containers of VS Code
I tried to touch the API of ebay
I tried to get CloudWatch data with Python
I tried to correct the keystone of the image
I tried to output LLVM IR with Python
I tried "binarizing" the image with Python + OpenCV