PIXELBANKv9.1.0
Menu

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:

  1. Extract a square patch centered at the keypoint
  2. Flatten the 2D patch into a 1D vector
  3. Normalize to unit length
normalized=v∥v∥2=v∑ivi2\text{normalized} = \frac{v}{\|v\|_2} = \frac{v}{\sqrt{\sum_i v_i^2}}

This technique is widely used in image matching and object recognition applications.

Example:

Input:
image = [[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]]
point = (1, 1)
patch_size = 3
Output:
[0.0596, 0.1191, 0.1787, 0.2382, 0.2978, 0.3573, 0.4169, 0.4764, 0.536]
Reasoning:
  1. Extract 3×3 patch centered at (1,1): [[1,2,3], [4,5,6], [7,8,9]]

  2. Flatten to 1D: [1, 2, 3, 4, 5, 6, 7, 8, 9]

  3. 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

  4. 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
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.