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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue