Keypoints and Descriptors - iffatAGheyas/computer-vision-handbook GitHub Wiki
🔑 Keypoints & Descriptors (SIFT, SURF, ORB)
Discover how to locate distinctive points in images (keypoints), describe their local neighbourhoods (descriptors) and compare methods in terms of speed, invariance and licence.
What Are Keypoints?
Keypoints are visually distinctive and stable points in an image—often corners, blobs or edges. Each keypoint encodes:
- Position: ((x, y)) coordinates
- Scale: size of the feature
- Orientation: angle of the feature
✅ Summary
Method | Descriptor | Best For |
---|---|---|
SIFT | 128 floats | Accuracy, scale invariance |
SURF | 64 floats | Speed + accuracy (licensed) |
ORB | 32 binary | Fast, open-source applications |
What Are Descriptors?
Descriptors are numerical vectors (e.g. 32–128 dimensions) that describe the local neighbourhood around a keypoint. Think of them as “fingerprints” you can compare across images to match keypoints.
Key Feature Detectors & Descriptors
Method | Type | Speed | Patent | Description |
---|---|---|---|---|
SIFT | Keypoints + Descriptors | Slow | Patented (pre-2020) | Robust to scale/rotation, precise |
SURF | Faster SIFT | Fast | Patented | Scale-invariant, faster but licensed |
ORB | Open-source + Fast | Fast | Free | Efficient alternative to SIFT/SURF |
🐍 ORB Example
import cv2
import matplotlib.pyplot as plt
# Load image in grayscale
img = cv2.imread("bird1.jpg", cv2.IMREAD_GRAYSCALE)
# Create ORB detector
orb = cv2.ORB_create()
# Detect keypoints and compute descriptors
keypoints, descriptors = orb.detectAndCompute(img, None)
# Draw keypoints
img_orb = cv2.drawKeypoints(img, keypoints, None, color=(0, 255, 0))
# Display
plt.imshow(img_orb, cmap='gray')
plt.title(f"ORB Keypoints: {len(keypoints)} found")
plt.axis("off")
plt.show()
🐍 SIFT Example
import cv2
import matplotlib.pyplot as plt
# Load image in grayscale
img = cv2.imread("bird1.jpg", cv2.IMREAD_GRAYSCALE)
# Create SIFT detector (requires opencv-contrib-python)
sift = cv2.SIFT_create()
# Detect keypoints and compute descriptors
keypoints, descriptors = sift.detectAndCompute(img, None)
# Draw rich keypoints
img_sift = cv2.drawKeypoints(
img, keypoints, None,
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS
)
# Display
plt.imshow(img_sift, cmap='gray')
plt.title(f"SIFT Keypoints: {len(keypoints)} found")
plt.axis("off")
plt.show()
Note: SIFT is available via opencv-contrib-python.
Descriptor Details
Feature | ORB | SIFT |
---|---|---|
Descriptor Size | 32 or 64 dimensions | 128 floats |
Data Type | Binary | Float32 |
Matching Speed | Very fast | Slower |
Rotation Invariance | ✅ | ✅ |
Scale Invariance | ❌ (partial) | ✅ |