Hough transform: Difference between revisions

mNo edit summary
(→‎{{header|Tcl}}: Added zkl)
Line 569:
 
* See [[Example:Hough transform/Tcl]]
 
=={{header|zkl}}==
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
{{trans|D}}
<lang zkl>const WHITE=0xffFFff, X=0x010101;
fcn houghTransform(image,hx=460,hy=360){
if(hy.isOdd) hy-=1; // hy argument must be even
out:=PPM(hx,hy,WHITE);
rMax:=image.w.toFloat().hypot(image.h);
dr,dTh:=rMax/(hy/2), (0.0).pi/hx;
 
foreach y,x in (image.h,image.w){
if(image[x,y]==WHITE) continue;
foreach iTh in (hx){
th,r:=dTh*iTh, th.cos()*x + th.sin()*y;
iry:=hy/2 + (r/dr + 0.5).floor(); // y==0 is top
if(out[iTh,iry]>0) out[iTh,iry]=out[iTh,iry] - X;
}
}
out
}</lang>
<lang zkl>fcn readPNG2PPM(fileName){
p:=System.popen("convert \"%s\" ppm:-".fmt(fileName),"r");
img:=PPM.readPPM(p);
p.close();
img
}
houghTransform(readPNG2PPM("pentagon.png"))
.write(File("pentagon_hough.ppm","wb"));</lang>
{{out}}
The output image looks the same as in the Go solution.
 
http://home.comcast.net/~zenkinetic/Images/pentagon_hough.jpg
 
{{omit from|PARI/GP}}
Anonymous user