Skip to content

Commit f3d0b7f

Browse files
authored
Update package.d doc for median filter example (#468)
1 parent e888555 commit f3d0b7f

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

source/mir/ndslice/package.d

+22-10
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ Returns:
360360
where с is the number of channels in the image.
361361
Dense data layout is guaranteed.
362362
+/
363-
Slice!(ubyte*, 3) movingWindowByChannel
364-
(Slice!(Universal, [3], ubyte*) image, size_t nr, size_t nc, ubyte delegate(Slice!(Universal, [2], ubyte*)) filter)
363+
Slice!(C*, 3) movingWindowByChannel(alias filter, C)
364+
(Slice!(C*, 3, Universal) image, size_t nr, size_t nc)
365365
{
366366
// 0. 3D
367367
// The last dimension represents the color channel.
@@ -374,10 +374,12 @@ Slice!(ubyte*, 3) movingWindowByChannel
374374
.windows(nr, nc)
375375
// 3. 5D
376376
// Unpacks the windows.
377-
.unpack
378-
.transposed!(0, 1, 4)
377+
.unpack.unpack
379378
// 4. 5D
380379
// Brings the color channel dimension to the third position.
380+
.transposed!(0, 1, 4)
381+
// 5. 3D Composed of 2D
382+
// Packs the last two dimensions.
381383
.pack!2
382384
// 2D to pixel lazy conversion.
383385
.map!filter
@@ -397,12 +399,15 @@ Params:
397399
Returns:
398400
median value over the range `r`
399401
+/
400-
T median(Range, T)(Slice!(Universal, [2], Range) sl, T[] buf)
402+
T median(Iterator, SliceKind kind, T)(Slice!(Iterator, 2, kind) sl, T[] buf)
401403
{
402404
import std.algorithm.sorting : topN;
403405
// copy sl to the buffer
404406
auto retPtr = reduce!(
405-
(ptr, elem) { *ptr = elem; return ptr + 1;} )(buf.ptr, sl);
407+
(ptr, elem) {
408+
*ptr = elem;
409+
return ptr + 1;
410+
} )(buf.ptr, sl);
406411
auto n = retPtr - buf.ptr;
407412
buf[0 .. n].topN(n / 2);
408413
return buf[n / 2];
@@ -414,9 +419,9 @@ The `main` function:
414419
-------
415420
void main(string[] args)
416421
{
417-
import std.conv : to;
418-
import std.getopt : getopt, defaultGetoptPrinter;
419-
import std.path : stripExtension;
422+
import std.conv: to;
423+
import std.getopt: getopt, defaultGetoptPrinter;
424+
import std.path: stripExtension;
420425
421426
uint nr, nc, def = 3;
422427
auto helpInformation = args.getopt(
@@ -434,6 +439,12 @@ void main(string[] args)
434439
435440
auto buf = new ubyte[nr * nc];
436441
442+
if (args.length == 1)
443+
{
444+
import std.stdio: writeln;
445+
writeln("No input file given");
446+
}
447+
437448
foreach (name; args[1 .. $])
438449
{
439450
import imageformats; // can be found at code.dlang.org
@@ -442,6 +453,7 @@ void main(string[] args)
442453
443454
auto ret = image.pixels
444455
.sliced(cast(size_t)image.h, cast(size_t)image.w, cast(size_t)image.c)
456+
.universal
445457
.movingWindowByChannel
446458
!(window => median(window, buf))
447459
(nr, nc);
@@ -450,7 +462,7 @@ void main(string[] args)
450462
name.stripExtension ~ "_filtered.png",
451463
ret.length!1,
452464
ret.length!0,
453-
(&ret[0, 0, 0])[0 .. ret.elementCount]);
465+
ret.field);
454466
}
455467
}
456468
-------

0 commit comments

Comments
 (0)