# Regular Meeting (2020.3.2) ## Hough transform for curve The curve eq. in x-y space, we can express with: $$(x-h)^2 + (y-k)^2 = r^2 ...eq.1$$ ![cir_eq](https://i.imgur.com/XwdSkuE.png) If a center point of circuit at $(0,0)$, then we can assume: $$h = r cos(t)$$ $$k = r sin(t)$$ Substituting $r cos(t)$ and $r sin(t)$ into $(h,k)$ of $eq.1$, we can obtain: $$(x-r cos(t))^2 + (y-r sin(t))^2 = r^2 ...eq.2$$ Arranging $eq.2$: $$r = \frac{1}{2} \frac{x^2 + y^2}{x cos(t) + y sin(t)} ...eq.3$$ [Demo](https://www.youtube.com/watch?v=Ltqt24SQQoI): ![demo-hct](https://imgur.com/EbnY69p.gif) Now, assume that we have the eqution of circit $$(x-0)^2 + (y-0)^2 = 5^2 ...eq.4$$ its chart and some points: ![eq_cir_00](https://i.imgur.com/BY18S2Z.png) We mapping $f(x,y) -> g(t,r)$ where $t = rad. degree,$ $r=eq.3$ Using these points(above chart) ``` [0,5] [3,4] [5,0] [0,-5] [-4,-3] ``` plot $g(t,r)$ of $eq.4$ We get **error**(python with matplotlib, numpy, math) ``` bash $ python ./hough-curve-space-2D.py Traceback (most recent call last): File "./hough-curve-space-2D.py", line 35, in <module> theta File "./hough-curve-space-2D.py", line 24, in get_hough_spcae r_axis[i] = numerator / denominator ZeroDivisionError: float division by zero ``` Because denominator of $eq.3$ is 0. The denominator $x cos(t) + y sin(t)$ of $eq.3$ goes to **0** very easy, for example: { `t = 0` **or** `x = 0` **or** `y = 0` } But numerator not, if the numerator $x^2 + y^2$ of $eq.3$ goes to **0**, only the condition { `x = 0` **and** `y = 0` } can be satisfied. So we swap denominator and numerator from $eq.3$ $$\frac{1}{r} = 2 \frac{x cos(t) + y sin(t)} {x^2 + y^2} ...eq.5$$ [code](https://github.com/curly-wei/small_program_training/blob/master/python_training/hough/hough-curve-spce-2D-1r.py) But the chart... ![1r-chart](https://i.imgur.com/yFoiWOW.png) ###### tags: `Regular Meeting` `DeWei`