MCPcopy Create free account
hub / github.com/davisking/dlib / py_label_connected_blobs

Function py_label_connected_blobs

tools/python/src/image.cpp:102–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101template <typename T>
102py::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

Callers

nothing calls this directly

Calls 9

label_connected_blobsFunction · 0.85
make_tupleFunction · 0.85
neighbors_4Class · 0.50
connected_if_equalClass · 0.50
neighbors_8Class · 0.50
neighbors_24Class · 0.50

Tested by

no test coverage detected