Complete the code to extract features from an image using a simple method.
import cv2 image = cv2.imread('image.jpg', 0) features = cv2.Canny(image, [1], 150) print(features.shape)
The Canny edge detector requires two threshold values. Here, 100 is a common lower threshold to detect edges.
Complete the code to compute Histogram of Oriented Gradients (HOG) features from an image.
from skimage.feature import hog from skimage import data, exposure image = data.astronaut() features, hog_image = hog(image, pixels_per_cell=(8, 8), cells_per_block=(2, 2), visualize=True, [1]=True) print(features.shape)
The 'multichannel=True' parameter tells the function to treat the input as a color image.
Fix the error in the code to extract SIFT features from an image.
import cv2 image = cv2.imread('image.jpg', 0) sift = cv2.SIFT_create() keypoints, descriptors = sift.[1](image) print(len(keypoints))
The correct method to detect keypoints and compute descriptors in one step is 'detectAndCompute'.
Fill both blanks to create a dictionary of feature descriptors for each keypoint.
features_dict = [1](kp.pt: desc for kp, desc in zip(keypoints, [2])) print(len(features_dict))
We use 'dict' to create a dictionary, and 'descriptors' holds the feature vectors for each keypoint.
Fill all three blanks to filter features with descriptor length greater than 100.
filtered_features = {kp: desc for kp, desc in features_dict.items() if len(desc) [1] [2]
print(len(filtered_features))
threshold = [3]The code filters descriptors with length greater than 100, so the operator is '>' and threshold is 100.