* 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 */
| 45 | * neighbor in the provided local neighborhood window |
| 46 | */ |
| 47 | array 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 |