MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / getRandomNeighbor

Function getRandomNeighbor

examples/image_processing/filters.cpp:47–57  ·  view source on GitHub ↗

* Retrieve a new image of same dimensions of the original image * where each original image's pixel is replaced by randomly picked * neighbor in the provided local neighborhood window */

Source from the content-addressed store, hash-verified

45 * neighbor in the provided local neighborhood window
46 */
47array getRandomNeighbor(const array &in, int windW, int windH) {
48 array rnd = 2.0f * randu(in.dims(0), in.dims(1)) - 1.0f;
49 array sx = seq(in.dims(0));
50 array sy = seq(in.dims(1));
51 array vx = tile(sx, 1, in.dims(1)) + floor(rnd * windW);
52 array vy = tile(sy.T(), in.dims(0), 1) + floor(rnd * windH);
53 array vxx = clamp(vx, 0, in.dims(0));
54 array vyy = clamp(vy, 0, in.dims(1));
55 array in2 = moddims(in, vx.elements(), 3);
56 return moddims(in2(vyy * in.dims(0) + vxx, span), in.dims());
57}
58
59/**
60 * randomly pick neighbor from given window size and replace the

Callers 2

spreadFunction · 0.85
pickFunction · 0.85

Calls 9

randuFunction · 0.85
seqClass · 0.85
floorFunction · 0.85
moddimsFunction · 0.85
TMethod · 0.80
clampFunction · 0.70
tileFunction · 0.50
dimsMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected