Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
39
Task/Hough-transform/D/hough-transform.d
Normal file
39
Task/Hough-transform/D/hough-transform.d
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import std.math, grayscale_image;
|
||||
|
||||
Image!Gray houghTransform(in Image!Gray im,
|
||||
in size_t hx=460, in size_t hy=360)
|
||||
pure nothrow in {
|
||||
assert(im !is null);
|
||||
assert(hx > 0 && hy > 0);
|
||||
assert((hy & 1) == 0, "hy argument must be even.");
|
||||
} body {
|
||||
auto result = new Image!Gray(hx, hy);
|
||||
result.clear(Gray.white);
|
||||
|
||||
immutable double rMax = hypot(im.nx, im.ny);
|
||||
immutable double dr = rMax / (hy / 2.0);
|
||||
immutable double dTh = PI / hx;
|
||||
|
||||
foreach (immutable y; 0 .. im.ny) {
|
||||
foreach (immutable x; 0 .. im.nx) {
|
||||
if (im[x, y] == Gray.white)
|
||||
continue;
|
||||
foreach (immutable iTh; 0 .. hx) {
|
||||
immutable double th = dTh * iTh;
|
||||
immutable double r = x * cos(th) + y * sin(th);
|
||||
immutable iry = hy / 2 - cast(int)floor(r / dr + 0.5);
|
||||
if (result[iTh, iry] > Gray(0))
|
||||
result[iTh, iry]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
(new Image!RGB)
|
||||
.loadPPM6("Pentagon.ppm")
|
||||
.rgb2grayImage()
|
||||
.houghTransform()
|
||||
.savePGM("Pentagon_hough.pgm");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue