| 100 | |
| 101 | template <typename T> |
| 102 | py::tuple py_label_connected_blobs ( |
| 103 | const numpy_image<T>& img, |
| 104 | bool zero_pixels_are_background, |
| 105 | int neighborhood_connectivity, |
| 106 | bool connected_if_both_not_zero |
| 107 | ) |
| 108 | { |
| 109 | DLIB_CASSERT(neighborhood_connectivity == 4 || |
| 110 | neighborhood_connectivity == 8 || |
| 111 | neighborhood_connectivity == 24); |
| 112 | |
| 113 | unsigned long num_blobs = 0; |
| 114 | |
| 115 | numpy_image<uint32_t> labels; |
| 116 | |
| 117 | if (zero_pixels_are_background && neighborhood_connectivity == 4 && connected_if_both_not_zero ) |
| 118 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_4(), ::connected_if_both_not_zero(), labels); |
| 119 | else if (zero_pixels_are_background && neighborhood_connectivity == 4 && !connected_if_both_not_zero ) |
| 120 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_4(), connected_if_equal(), labels); |
| 121 | else if (!zero_pixels_are_background && neighborhood_connectivity == 4 && connected_if_both_not_zero ) |
| 122 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_4(), ::connected_if_both_not_zero(), labels); |
| 123 | else if (!zero_pixels_are_background && neighborhood_connectivity == 4 && !connected_if_both_not_zero ) |
| 124 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_4(), connected_if_equal(), labels); |
| 125 | |
| 126 | else if (zero_pixels_are_background && neighborhood_connectivity == 8 && connected_if_both_not_zero ) |
| 127 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_8(), ::connected_if_both_not_zero(), labels); |
| 128 | else if (zero_pixels_are_background && neighborhood_connectivity == 8 && !connected_if_both_not_zero ) |
| 129 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_8(), connected_if_equal(), labels); |
| 130 | else if (!zero_pixels_are_background && neighborhood_connectivity == 8 && connected_if_both_not_zero ) |
| 131 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_8(), ::connected_if_both_not_zero(), labels); |
| 132 | else if (!zero_pixels_are_background && neighborhood_connectivity == 8 && !connected_if_both_not_zero ) |
| 133 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_8(), connected_if_equal(), labels); |
| 134 | |
| 135 | else if (zero_pixels_are_background && neighborhood_connectivity == 24 && connected_if_both_not_zero ) |
| 136 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_24(), ::connected_if_both_not_zero(), labels); |
| 137 | else if (zero_pixels_are_background && neighborhood_connectivity == 24 && !connected_if_both_not_zero ) |
| 138 | num_blobs = label_connected_blobs(img, ::zero_pixels_are_background(), neighbors_24(), connected_if_equal(), labels); |
| 139 | else if (!zero_pixels_are_background && neighborhood_connectivity == 24 && connected_if_both_not_zero ) |
| 140 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_24(), ::connected_if_both_not_zero(), labels); |
| 141 | else if (!zero_pixels_are_background && neighborhood_connectivity == 24 && !connected_if_both_not_zero ) |
| 142 | num_blobs = label_connected_blobs(img, nothing_is_background(), neighbors_24(), connected_if_equal(), labels); |
| 143 | else |
| 144 | DLIB_CASSERT(false, "this should never happen"); |
| 145 | |
| 146 | return py::make_tuple(labels, num_blobs); |
| 147 | } |
| 148 | |
| 149 | // ---------------------------------------------------------------------------------------- |
| 150 |
nothing calls this directly
no test coverage detected