Normalized Patch Descriptor
Implement a feature descriptor known as a Normalized Patch Descriptor, which is crucial for feature matching in computer vision. You are given an image and a keypoint location, and need to extract a normalized patch descriptor for feature matching.
The concept of a patch descriptor is rooted in capturing the local appearance around a keypoint, which is essential for tasks like object recognition and tracking. This involves extracting a square patch centered at the keypoint, flattening it into a 1D vector, and then normalizing it to unit length using L2 normalization, making the descriptor invariant to linear intensity changes such as brightness and contrast.
Here are the steps to achieve this:
- Extract a square patch centered at the keypoint
- Flatten the 2D patch into a 1D vector
- Normalize to unit length
This technique is widely used in image matching and object recognition applications.
Example
image = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
point = (1, 1)
patch_size = 3[0.0596, 0.1191, 0.1787, 0.2382, 0.2978, 0.3573, 0.4169, 0.4764, 0.536]
-
Extract 3×3 patch centered at (1,1): [[1,2,3], [4,5,6], [7,8,9]]
-
Flatten to 1D: [1, 2, 3, 4, 5, 6, 7, 8, 9]
-
Calculate L2 norm: ||v|| = √(1² + 2² + 3² + 4² + 5² + 6² + 7² + 8² + 9²) = √(1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81) = √285 ≈ 16.882
-
Normalize each element: [1/16.882, 2/16.882, ..., 9/16.882] = [0.0592, 0.1185, 0.1777, 0.2369, 0.2962, 0.3554, 0.4146, 0.4739, 0.5331]
Rounded to 4 decimals.
Constraints
- image is a 2D grayscale image
- point is (row, col) center of the patch
- patch_size is an odd number (the patch is patch_size × patch_size)
- Assume the point has enough padding for the full patch
- Return flattened, normalized descriptor with values rounded to 4 decimals