Hough transform: Difference between revisions

Added BBC BASIC
(Added Java implementation.)
(Added BBC BASIC)
Line 8:
 
There is also a spherical Hough transform, which is more suited to identifying planes in 3D data.
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
BBC BASIC uses Cartesian coordinates so the image is 'upside down' compared with some other solutions.
[[Image:hough_bbc.gif|right]]
<lang bbcbasic> Width% = 320
Height% = 240
VDU 23,22,Width%;Height%;8,16,16,128
*DISPLAY Pentagon.bmp
OFF
DIM hist%(Width%-1, Height%-1)
rs = 2 * SQR(Width%^2 + Height%^2) / Height% : REM Radial step
ts = PI / Width% : REM Angular step
h% = Height% / 2
REM Hough transform:
FOR y% = 0 TO Height%-1
FOR x% = 0 TO Width%-1
IF TINT(x%*2, y%*2) = 0 THEN
FOR t% = 0 TO Width%-1
th = t% * ts
r% = (x%*COS(th) + y%*SIN(th)) / rs + h% + 0.5
hist%(t%,r%) += 1
NEXT
ENDIF
NEXT
NEXT y%
REM Find max:
max% = 0
FOR y% = 0 TO Height%-1
FOR x% = 0 TO Width%-1
IF hist%(x%,y%) > max% max% = hist%(x%,y%)
NEXT
NEXT y%
REM Plot:
GCOL 1
FOR y% = 0 TO Height%-1
FOR x% = 0 TO Width%-1
c% = 255 * hist%(x%,y%) / max%
COLOUR 1, c%, c%, c%
LINE x%*2,y%*2,x%*2,y%*2
NEXT
NEXT y%
REPEAT
WAIT 1
UNTIL FALSE</lang>
 
=={{header|C}}==
Line 265 ⟶ 317:
}</lang>
This program takes a pnm file (binary, either P5 or P6) and does the transformation, then dump output onto stdout. Sample images below are output from the pentagram; sample lines with added noise; output of processing that. Both output were with 1.5 gamma.
 
=={{header|Go}}==
[[file:GoHough.png|right|thumb|Output png]]