Anonymous user
Canny edge detector: Difference between revisions
Small improvements in the D entry
(More idiomatic D code) |
(Small improvements in the D entry) |
||
Line 533:
in float[] kernel,
in int nx, in int ny, in int kn)
pure nothrow in {
assert(kernel.length == kn ^^ 2);
assert(inp.length == outp.length);
} body {
//immutable int kn = sqrti(kernel.length);
immutable int khalf = kn / 2;
float pMin = float.max, pMax = -float.max;▼
static if (normalize) {
▲ float pMin = float.max, pMax = -float.max;
foreach (m; khalf .. nx - khalf) {
foreach (n; khalf .. ny - khalf) {
float pixel = 0.0;
foreach (j; -khalf .. khalf + 1) {
foreach (i; -khalf .. khalf + 1) {
Line 558 ⟶ 563:
foreach (n; khalf .. ny - khalf) {
float pixel = 0.0;
foreach (j; -khalf .. khalf + 1) {
foreach (i; -khalf .. khalf + 1) {
Line 587 ⟶ 592:
*/
void gaussianFilter(in Pixel[] inp, Pixel[] outp,
in int nx, in int ny, float sigma) nothrow
in {
assert(inp.length == outp.length);
} body {
immutable int n = 2 * cast(int)(2 * sigma) + 3;
/*enum*/ immutable float mean = cast(float)floor(n / 2.0);
Line 596 ⟶ 604:
n, sigma);
foreach (i; 0 .. n) {
foreach (j; 0 .. n) {
Line 629 ⟶ 637:
gaussianFilter(inp, outp, nx, ny, sigma);
auto after_Gx = new Pixel[nx * ny];▼
convolution!(false)(outp, after_Gx, Gx, nx, ny, 3);▼
▲ auto after_Gx = new Pixel[nx * ny];
auto after_Gy = new Pixel[nx * ny];
▲ convolution!(false)(outp, after_Gx, Gx, nx, ny, 3);
convolution!(false)(outp, after_Gy, Gy, nx, ny, 3);
Line 646 ⟶ 652:
foreach (i; 1 .. nx - 1)
foreach (j; 1 .. ny - 1) {
immutable
G[c] = cast(Pixel)hypot(after_Gx[c], after_Gy[c]);
}
|