76 const struct blob *x = (
const struct blob *) a;
77 const struct blob *y = (
const struct blob *) b;
85 const struct blob *x = (
const struct blob *) a;
86 const struct blob *y = (
const struct blob *) b;
107 const struct label *x = (
const struct label *) a;
108 const struct label *y = (
const struct label *) b;
159 if (xroot == yroot) {
return; }
172 struct ufs *
ufs = (
struct ufs *)calloc(1,
sizeof(
struct ufs));
173 ufs->
width = i1 - i0;
176 ufs->
nodes = (
struct uf *) calloc(1, pixels *
sizeof(
struct uf));
177 memset(ufs->
nodes, -1, pixels *
sizeof(
struct uf));
179 int maximum = pixels;
181 for (
int j = j0;
j < j1; ++
j) {
182 for (
int i = i0;
i < i1; ++
i) {
183 int ki =
j * width +
i;
184 int ko = (
j - j0) * ufs->
width + (i - i0);
185 if (glitched[ki] != 0.0f) {
186 int kileft =
j * width + i - 1;
187 int koleft = (
j - j0) * ufs->
width + (i - i0) - 1;
190 if (strategy ==
blob_boolean ? glitched[kileft] != 0.0f : glitched[kileft] == glitched[ki]) {
194 int kiabove = (
j - 1) * width + i;
195 int koabove = ((
j - j0) - 1) * ufs->
width + (i - i0);
198 if (strategy ==
blob_boolean ? glitched[kiabove] != 0.0f : glitched[kiabove] == glitched[ki]) {
206 if (left == maximum && above == maximum) {
208 }
else if (left == maximum) {
211 }
else if (above == maximum) {
215 ufs->
labels[ko].
label = left < above ? left : above;
222 for (
int j = j0;
j < j1; ++
j) {
223 for (
int i = i0;
i < i1; ++
i) {
224 int ki =
j * width +
i;
225 int ko = (
j - j0) * ufs->
width + (i - i0);
226 if (glitched[ki] != 0.0f) {
232 struct label *labels = (
struct label *) malloc(pixels *
sizeof(
struct label));
233 memcpy(labels, ufs->
labels, pixels *
sizeof(
struct label));
244 struct blob *blobs = (
struct blob *) calloc(pixels,
sizeof(
struct blob));
246 for (
int k = 0; k < pixels; ++k) {
247 if (labels[k].
label == 0) {
250 if (labels[k].
label == last) {
254 min_i =
min(min_i, labels[k].
i);
255 max_i =
max(max_i, labels[k].i);
256 min_j =
min(min_j, labels[k].
j);
257 max_j =
max(max_j, labels[k].j);
259 if (labels[k].
label != last || k == pixels - 1) {
261 blobs[index].
label = last;
272 last = labels[k].
label;
279 error = labels[k].
error;
283 free(labels); labels = 0;
299 struct blob *
find_blobs1(
int *blob_count,
int width,
int height,
const float *glitched) {