Hough transform: Difference between revisions
Content deleted Content added
→{{header|J}}: Add draft |
|||
Line 136: | Line 136: | ||
[[Image:Houghtrasf-c.png|thumb|left|360x200px|Output image when input is the given Pentagon.]] |
[[Image:Houghtrasf-c.png|thumb|left|360x200px|Output image when input is the given Pentagon.]] |
||
<br style="clear:both" /> |
<br style="clear:both" /> |
||
=={{header|J}}== |
|||
'''Solution:''' |
|||
<lang j>NB.*houghTransform v Produces a density plot of image y in hough space |
|||
NB. y is picture as an array with 1 at non-white points, |
|||
NB. x is resolution (width,height) of resulting image |
|||
houghTransform=: dyad define |
|||
'w h'=. x NB. width and height of target image |
|||
theta=. o. (%~ 0.5+i.) w NB. theta in radians from 0 to π |
|||
rho=. (2 1 o./theta) +/ .*~ 4$.$. |.y NB. rho for each pixel at each theta |
|||
'min max'=. (,~-) +/&.:*: $y NB. min/max possible rho |
|||
rho=. <. 0.5+ h * (rho-min) % max-min NB. Rescale rho from 0 to h and round to int |
|||
|.([: <:@(#/.~) (i.h)&,)"1&.|: rho NB. consolidate into picture |
|||
)</lang> |
|||
'''Example use:''' |
|||
<lang j> require 'viewmat media/platimg' |
|||
Img=: readimg jpath '~temp/pentagon.png' |
|||
viewmat 320 240 houghTransform _1 > Img</lang> |
|||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |