Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
45
Task/Hough-transform/SequenceL/hough-transform-1.sequencel
Normal file
45
Task/Hough-transform/SequenceL/hough-transform-1.sequencel
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import <Utilities/Sequence.sl>;
|
||||
import <Utilities/Math.sl>;
|
||||
|
||||
hough: int(2) * int * int * int -> int(2);
|
||||
hough(image(2), thetaAxisSize, rAxisSize, minContrast) :=
|
||||
let
|
||||
initialResult[r,theta] := 0 foreach r within 1 ... rAxisSize, theta within 1 ... thetaAxisSize;
|
||||
|
||||
result := houghHelper(image, minContrast, 1, 1, initialResult);
|
||||
|
||||
max := vectorMax(vectorMax(result));
|
||||
in
|
||||
255 - min(round((result * 255 / max)), 255);
|
||||
|
||||
houghHelper(image(2), minContrast, x, y, result(2)) :=
|
||||
let
|
||||
thetaAxisSize := size(head(result));
|
||||
rAxisSize := size(result);
|
||||
|
||||
width := size(head(image));
|
||||
height := size(image);
|
||||
maxRadius := ceiling(sqrt(width^2 + height^2));
|
||||
halfRAxisSize := rAxisSize / 2;
|
||||
|
||||
rs[theta] := round((cos(theta) * x + sin(theta) * y) * halfRAxisSize / maxRadius) + halfRAxisSize
|
||||
foreach theta within (0 ... (thetaAxisSize-1)) * pi / thetaAxisSize;
|
||||
|
||||
newResult[r,theta] := result[r,theta] + 1 when rs[theta] = r-1 else result[r,theta];
|
||||
|
||||
nextResult := result when not checkContrast(image, x, y, minContrast) else newResult;
|
||||
|
||||
nextX := 1 when x = width else x + 1;
|
||||
nextY := y + 1 when x = width else y;
|
||||
in
|
||||
nextResult when x = width and y = height
|
||||
else
|
||||
houghHelper(image, minContrast, nextX, nextY, nextResult);
|
||||
|
||||
checkContrast(image(2), x, y, minContrast) :=
|
||||
let
|
||||
neighbors[i,j] := image[i,j] when i > 0 and i < size(image) and j > 0 and j < size(image[i])
|
||||
foreach i within y-1 ... y+1,
|
||||
j within x-1 ... x+1;
|
||||
in
|
||||
some(some(abs(image[y,x] - neighbors) >= minContrast));
|
||||
39
Task/Hough-transform/SequenceL/hough-transform-2.sequencel
Normal file
39
Task/Hough-transform/SequenceL/hough-transform-2.sequencel
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "SL_Generated.h"
|
||||
#include "CImg.h"
|
||||
|
||||
using namespace cimg_library;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
string fileName = "Pentagon.bmp";
|
||||
if(argc > 1) fileName = argv[1];
|
||||
int thetaAxisSize = 640; if(argc > 2) thetaAxisSize = atoi(argv[2]);
|
||||
int rAxisSize = 480; if(argc > 3) rAxisSize = atoi(argv[3]);
|
||||
int minContrast = 64; if(argc > 4) minContrast = atoi(argv[4]);
|
||||
int threads = 0; if(argc > 5) threads = atoi(argv[5]);
|
||||
char titleBuffer[200];
|
||||
SLTimer t;
|
||||
|
||||
CImg<int> image(fileName.c_str());
|
||||
int imageDimensions[] = {image.height(), image.width(), 0};
|
||||
Sequence<Sequence<int> > imageSeq((void*) image.data(), imageDimensions);
|
||||
Sequence< Sequence<int> > result;
|
||||
|
||||
sl_init(threads);
|
||||
|
||||
t.start();
|
||||
sl_hough(imageSeq, thetaAxisSize, rAxisSize, minContrast, threads, result);
|
||||
t.stop();
|
||||
|
||||
CImg<int> resultImage(result[1].size(), result.size());
|
||||
for(int y = 0; y < result.size(); y++)
|
||||
for(int x = 0; x < result[y+1].size(); x++)
|
||||
resultImage(x,result.size() - 1 - y) = result[y+1][x+1];
|
||||
|
||||
sprintf(titleBuffer, "SequenceL Hough Transformation: %d X %d Image to %d X %d Result | %d Cores | Processed in %f sec\0",
|
||||
image.width(), image.height(), resultImage.width(), resultImage.height(), threads, t.getTime());
|
||||
resultImage.display(titleBuffer);
|
||||
|
||||
sl_done();
|
||||
return 0;
|
||||
}
|
||||
36
Task/Hough-transform/Sidef/hough-transform.sidef
Normal file
36
Task/Hough-transform/Sidef/hough-transform.sidef
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
require('Imager')
|
||||
|
||||
func hough(im, width=460, height=360) {
|
||||
|
||||
height = 2*floor(height / 2)
|
||||
|
||||
var xsize = im.getwidth
|
||||
var ysize = im.getheight
|
||||
|
||||
var ht = %s|Imager|.new(xsize => width, ysize => height)
|
||||
var canvas = height.of { width.of(255) }
|
||||
|
||||
ht.box(filled => true, color => 'white')
|
||||
|
||||
var rmax = hypot(xsize, ysize)
|
||||
var dr = 2*(rmax / height)
|
||||
var dth = (Num.pi / width)
|
||||
|
||||
for y,x in (^ysize ~X ^xsize) {
|
||||
var col = im.getpixel(x => x, y => y)
|
||||
var (r,g,b) = col.rgba
|
||||
(r==255 && g==255 && b==255) && next
|
||||
for k in ^width {
|
||||
var th = dth*k
|
||||
var r = (x*cos(th) + y*sin(th))
|
||||
var iry = (height/2 + int(r/dr + 0.5))
|
||||
ht.setpixel(x => k, y => iry, color => 3.of(--canvas[iry][k]))
|
||||
}
|
||||
}
|
||||
|
||||
return ht
|
||||
}
|
||||
|
||||
var img = %s|Imager|.new(file => 'Pentagon.png')
|
||||
var ht = hough(img)
|
||||
ht.write(file => 'Hough transform.png')
|
||||
Loading…
Add table
Add a link
Reference in a new issue