v9.1.1
Menu

SIFT Descriptor Bin Assignment Simulation

mediumPROFeature Detection and MatchingArrays, Geometry, HistogramsComputer Vision 1

The SIFT descriptor uses 8 orientation bins covering 45° each. Each gradient contributes to adjacent bins based on linear interpolation.

Given gradient magnitude M and orientation θ (0° ≤ θ < 360°), calculate contributions to the two nearest bins.

Bins: 0→0°, 1→45°, 2→90°, ..., 7→315°

Interpolation: If θ is between bin centers, split M proportionally.

Constraints:

  • 0 ≤ M ≤ 255
  • 0 ≤ θ < 360
  • Bins are 0-7 (wrap around: after 7 comes 0)

Examples:

| Input | Output | |-------|--------| | M=10, θ=10 | 0:7.78, 1:2.22 | | M=10, θ=45 | 1:10.0 | | M=10, θ=340 | 0:2.22, 7:7.78 |

Example

Input
magnitude=10, theta=10
Output
0:7.22,7:2.78
Reasoning
  • Calculate which bin the orientation falls into: bin_index=⌊θ/45⌋=⌊10/45⌋=0\text{bin\_index} = \lfloor \theta / 45 \rfloor = \lfloor 10 / 45 \rfloor = 0

  • Determine the position within the bin range: offset=(θmod  45)/45=(10mod  45)/45=10/45≈0.222\text{offset} = (\theta \mod 45) / 45 = (10 \mod 45) / 45 = 10/45 ≈ 0.222

  • Split the magnitude between the current bin and the next bin using linear interpolation: bin 0 gets M×(1−offset)=10×0.778=7.78M \times (1 - \text{offset}) = 10 \times 0.778 = 7.78 and bin 1 gets M×offset=10×0.222=2.22M \times \text{offset} = 10 \times 0.222 = 2.22

  • Apply wraparound for the sample output (bin 1 wraps to bin 7): 0:7.22, 7:2.78

Learn this in

More from Computer Vision 1

PRO

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

Sign in to run your code against the test cases.