| 60 | } |
| 61 | |
| 62 | int main(int argc, char** argv) { |
| 63 | try { |
| 64 | int device = argc > 1 ? atoi(argv[1]) : 0; |
| 65 | af::setDevice(device); |
| 66 | af::info(); |
| 67 | |
| 68 | array bimodal = |
| 69 | loadImage(ASSETS_DIR "/examples/images/noisy_square.png", false); |
| 70 | bimodal = resize(0.75f, bimodal); |
| 71 | |
| 72 | array bt = threshold(bimodal, 180.0f); |
| 73 | array ot = otsu(bimodal); |
| 74 | array bimodHist = histogram(bimodal, 256, 0, 255); |
| 75 | array smooth = convolve(bimodal, gaussianKernel(5, 5)); |
| 76 | array smoothHist = histogram(smooth, 256, 0, 255); |
| 77 | |
| 78 | af::Window wnd(1536, 1024, "Binary Thresholding Algorithms"); |
| 79 | printf("Press ESC while the window is in focus to proceed to exit\n"); |
| 80 | |
| 81 | wnd.grid(3, 3); |
| 82 | wnd(0, 1).setAxesTitles("Bins", "Frequency"); |
| 83 | wnd(1, 1).setAxesTitles("Bins", "Frequency"); |
| 84 | wnd(2, 1).setAxesTitles("Bins", "Frequency"); |
| 85 | while (!wnd.close()) { |
| 86 | wnd(0, 0).image(bimodal / 255, "Input Image"); |
| 87 | wnd(1, 0).image(bimodal / 255, "Input Image"); |
| 88 | wnd(2, 0).image(smooth / 255, "Input Smoothed by Gaussian Filter"); |
| 89 | wnd(0, 1).hist(bimodHist, 0, 255, "Input Histogram"); |
| 90 | wnd(1, 1).hist(bimodHist, 0, 255, "Input Histogram"); |
| 91 | wnd(2, 1).hist(smoothHist, 0, 255, "Smoothed Input Histogram"); |
| 92 | wnd(0, 2).image(bt, "Simple Binary threshold"); |
| 93 | wnd(1, 2).image(ot, "Otsu's Threshold"); |
| 94 | wnd(2, 2).image(otsu(smooth), "Otsu's Threshold on Smoothed Image"); |
| 95 | wnd.show(); |
| 96 | } |
| 97 | } catch (af::exception& e) { |
| 98 | fprintf(stderr, "%s\n", e.what()); |
| 99 | throw; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
nothing calls this directly
no test coverage detected