v9.1.1
Menu

Point to Hough Space

easyPROHough TransformsHoughCV: Feature Detection and Matching

Implement a function to transform a point from image coordinates to its representation in Hough space for line detection. The Hough transform is a feature extraction technique used in image processing to detect lines, circles, and other shapes. In the context of line detection, the Hough space is a 2D parameter space where lines are represented by their distance ρρ from the origin and the angle θθ of the perpendicular line to the x-axis.

To achieve this transformation, we need to compute ρρ for each θθ value, which forms a sinusoidal curve in Hough space.

  1. Start with a point in image coordinates (x,y)(x, y).
  2. For each angle θθ, calculate the corresponding ρρ value using the formula.
ρ=xcos⁡(θ)+ysin⁡(θ)\rho = x \cos(\theta) + y \sin(\theta)

This technique is widely used in computer vision applications, such as edge detection and object recognition.

Example

Input
point = (10, 10)
theta_values = [0, 45, 90]
Output
[10.0, 14.14, 10.0]
Reasoning
  • Input: point =(10,10)= (10, 10) is a single pixel location, and theta_values =[0,45,90]= [0, 45, 90] are angles in degrees of the normal to each candidate line through it. The trig in the formula expects radians, so these are 00, π/4\pi/4 and π/2\pi/2.
  • θ=0∘\theta = 0^\circ: cos⁡0=1\cos 0 = 1, sin⁡0=0\sin 0 = 0, so ρ=10⋅1+10⋅0=10\rho = 10 \cdot 1 + 10 \cdot 0 = 10. This is the vertical line x=10x = 10.
  • θ=45∘\theta = 45^\circ: cos⁡\cos and sin⁡\sin both equal 22≈0.7071\frac{\sqrt{2}}{2} \approx 0.7071, so ρ=7.0711+7.0711=14.1421\rho = 7.0711 + 7.0711 = 14.1421, which rounds to 14.1414.14. That is 10210\sqrt{2}, the full distance from the origin to (10,10)(10, 10).
  • θ=90∘\theta = 90^\circ: ρ=10⋅0+10⋅1=10\rho = 10 \cdot 0 + 10 \cdot 1 = 10, a horizontal line at height y=10y = 10.
  • Output: one ρ\rho per angle, in the same order, each rounded to 2 decimal places: [10.0, 14.14, 10.0].
  • Notice that 45∘45^\circ gives the largest ρ\rho here because that normal points straight at the pixel. Across all angles, the values trace a sinusoid in (θ,ρ)(\theta, \rho) space.

Constraints

  • point is (x, y) in image coordinates
  • theta_values is a list of angles in degrees
  • Return list of ρ values rounded to 2 decimal places

Learn this in

More from CV: Feature Detection and Matching

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.