| 44 | } |
| 45 | |
| 46 | array edge(const array &in, int method = 0) { |
| 47 | int w = 5; |
| 48 | if (in.dims(0) < 512) w = 3; |
| 49 | if (in.dims(0) > 2048) w = 7; |
| 50 | |
| 51 | int h = 5; |
| 52 | if (in.dims(0) < 512) h = 3; |
| 53 | if (in.dims(0) > 2048) h = 7; |
| 54 | |
| 55 | array ker = gaussianKernel(w, h); |
| 56 | array smooth = convolve(in, ker); |
| 57 | array mag, dir; |
| 58 | |
| 59 | switch (method) { |
| 60 | case 1: prewitt(mag, dir, smooth); break; |
| 61 | case 2: sobelFilter(mag, dir, smooth); break; |
| 62 | case 3: |
| 63 | mag = canny(in, AF_CANNY_THRESHOLD_AUTO_OTSU, 0.18, 0.54).as(f32); |
| 64 | break; |
| 65 | default: throw af::exception("Unsupported type"); |
| 66 | } |
| 67 | |
| 68 | return normalize(mag); |
| 69 | } |
| 70 | |
| 71 | void edge() { |
| 72 | af::Window myWindow("Edge Dectectors"); |
no test coverage detected