Demonstrates various image morphing manipulations.
| 68 | |
| 69 | // Demonstrates various image morphing manipulations. |
| 70 | static void morphing_demo() { |
| 71 | af::Window wnd(1280, 720, "Morphological Operations"); |
| 72 | // load images |
| 73 | array img_rgb = loadImage(ASSETS_DIR "/examples/images/man.jpg", true) / |
| 74 | 255.f; // 3 channel RGB [0-1] |
| 75 | |
| 76 | array mask = constant(1, 5, 5); |
| 77 | |
| 78 | array er = erode(img_rgb, mask); |
| 79 | array di = dilate(img_rgb, mask); |
| 80 | array op = morphopen(img_rgb, mask); |
| 81 | array cl = morphclose(img_rgb, mask); |
| 82 | array gr = morphgrad(img_rgb, mask); |
| 83 | array th = tophat(img_rgb, mask); |
| 84 | array bh = bottomhat(img_rgb, mask); |
| 85 | array bl = blur(img_rgb, gaussianKernel(5, 5)); |
| 86 | array bp = border(img_rgb, 20, 30, 40, 50, 0.5); |
| 87 | array bo = border(img_rgb, 20); |
| 88 | |
| 89 | while (!wnd.close()) { |
| 90 | wnd.grid(3, 4); |
| 91 | |
| 92 | wnd(0, 0).image(img_rgb, "Input"); |
| 93 | wnd(1, 0).image(er, "Erosion"); |
| 94 | wnd(2, 0).image(di, "Dilation"); |
| 95 | |
| 96 | wnd(0, 1).image(op, "Opening"); |
| 97 | wnd(1, 1).image(cl, "Closing"); |
| 98 | wnd(2, 1).image(gr, "Gradient"); |
| 99 | |
| 100 | wnd(0, 2).image(th, "TopHat"); |
| 101 | wnd(1, 2).image(bh, "BottomHat"); |
| 102 | wnd(2, 2).image(bl, "Blur"); |
| 103 | |
| 104 | wnd(0, 3).image(bp, "Border to Gray"); |
| 105 | wnd(1, 3).image(bo, "Border to black"); |
| 106 | |
| 107 | wnd.show(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | int main(int argc, char** argv) { |
| 112 | int device = argc > 1 ? atoi(argv[1]) : 0; |
no test coverage detected