| 88 | } |
| 89 | |
| 90 | void prewitt(array &mag, array &dir, const array &in) { |
| 91 | static float h1[] = {1, 1, 1}; |
| 92 | static float h2[] = {-1, 0, 1}; |
| 93 | static array h1d(3, h1); |
| 94 | static array h2d(3, h2); |
| 95 | |
| 96 | // Find the gradients |
| 97 | array Gy = af::convolve(h2d, h1d, in) / 6; |
| 98 | array Gx = af::convolve(h1d, h2d, in) / 6; |
| 99 | |
| 100 | // Find magnitude and direction |
| 101 | mag = hypot(Gx, Gy); |
| 102 | dir = atan2(Gy, Gx); |
| 103 | } |
| 104 | |
| 105 | void sobelFilter(array &mag, array &dir, const array &in) { |
| 106 | // Find the gradients |