Hough transform: Difference between revisions

(Undo revision 88705 by Coderjoe (Talk))
(→‎{{header|J}}: Add draft)
Line 136:
[[Image:Houghtrasf-c.png|thumb|left|360x200px|Output image when input is the given Pentagon.]]
<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}}==
892

edits