forked from victoroliv2/CCL-GPU
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccl_gold.cpp
More file actions
executable file
·42 lines (34 loc) · 778 Bytes
/
ccl_gold.cpp
File metadata and controls
executable file
·42 lines (34 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
namespace gold {
int find(int* label, int x) {
if (label[x] == x) {
return x;
}else {
int v = find(label, label[x]);
label[x] = v;
return v;
}
}
void merge(int* label, int x, int y){
x = find(label, x);
y = find(label, y);
if (label[x] < label[y]) {
label[y] = x;
}else {
label[x] = y;
}
}
void CCL(unsigned char* img, int w, int h, int* label) {
for (int i=0; i<w*h; i++) {
label[i] = i;
}
for (int i=0; i<w*h; i++) {
if (i%w>0 && img[i]==img[i-1]) merge(label, i, i-1);
if (i/w>0 && img[i]==img[i-w]) merge(label, i, i-w);
}
for (int i=0; i<w*h; i++) {
label[i] = find(label, i);
}
}
}