| 82 | } |
| 83 | |
| 84 | void brain_seg(bool console) { |
| 85 | af::Window wnd("Brain Segmentation Demo"); |
| 86 | wnd.setColorMap(AF_COLORMAP_HEAT); |
| 87 | |
| 88 | double time_total = 30; // run for N seconds |
| 89 | |
| 90 | array B = loadImage(ASSETS_DIR "/examples/images/brain.png"); |
| 91 | int slices = 256; |
| 92 | |
| 93 | B = moddims(B, dim4(B.dims(0), B.dims(1) / slices, slices)); |
| 94 | af::sync(); |
| 95 | |
| 96 | int N = 2 * slices - 1; |
| 97 | |
| 98 | timer t = timer::start(); |
| 99 | int iter = 0; |
| 100 | |
| 101 | /* loop forward and backward for 100 frames |
| 102 | * exit if the user presses escape or the animation |
| 103 | * ends |
| 104 | */ |
| 105 | for (int i = 0; !wnd.close(); i++) { |
| 106 | iter++; |
| 107 | |
| 108 | int j = i % N; |
| 109 | int k = std::min(j, N - j); |
| 110 | array Bi = B(span, span, k); |
| 111 | |
| 112 | /* process */ |
| 113 | array Si = segment_volume(B, k); |
| 114 | array Ei = edges_slice(Si); |
| 115 | array Mi = meanShift(Bi, 10, 10, 5); |
| 116 | |
| 117 | /* visualization */ |
| 118 | if (!console) { |
| 119 | wnd.grid(2, 2); |
| 120 | |
| 121 | wnd(0, 0).image(Bi / 255.f, "Input"); |
| 122 | wnd(1, 0).image(Ei, "Edges"); |
| 123 | wnd(0, 1).image(Mi / 255.f, "Meanshift"); |
| 124 | wnd(1, 1).image(Si, "Segmented"); |
| 125 | |
| 126 | wnd.show(); |
| 127 | } else { |
| 128 | /* sync the operations so that current |
| 129 | * iteration comptation finishes |
| 130 | * */ |
| 131 | af::sync(); |
| 132 | } |
| 133 | |
| 134 | /* we have had ran throuh simlation results |
| 135 | * exit the rendering loop */ |
| 136 | if (!progress(iter, t, time_total)) break; |
| 137 | if (!(i < 100 * N)) break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | int main(int argc, char* argv[]) { |
no test coverage detected