Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9caf6b4
perf: faster labeling3d_naive.h
william-silversmith Jun 20, 2026
807aa40
fix: qualify move with std::move
william-silversmith Jun 20, 2026
d15a078
fix: qualify CheckAlg with override
william-silversmith Jun 20, 2026
97b6ff4
perf: faster relabel for labeling3D_PRED_2021.h
william-silversmith Jun 20, 2026
28e8483
perf: faster relabel for labeling3D_PREDpp_2021
william-silversmith Jun 20, 2026
2ce6db9
perf: faster labeling3D_SAUF_2021
william-silversmith Jun 20, 2026
f408874
perf: faster labeling3D_SAUFpp_2021 relabeling
william-silversmith Jun 20, 2026
52b0153
perf: faster relabeling for labeling_grana_2016
william-silversmith Jun 20, 2026
001d479
perf: labeling_he_2008 faster relabel
william-silversmith Jun 20, 2026
b2d7968
perf: faster labeling_he_2014 relabel
william-silversmith Jun 20, 2026
883ddab
perf: faster relabel for labeling_PREDpp_2021
william-silversmith Jun 20, 2026
c6ee0fb
perf: faster labeling_sauf_4c relabeling
william-silversmith Jun 20, 2026
220246e
perf: faster labeling_sauf_background relabel
william-silversmith Jun 20, 2026
db302d8
perf: faster relabel for labeling_wu_2009
william-silversmith Jun 20, 2026
904e382
fix: don't convert MemGetLabel for labeling_wu_2009
william-silversmith Jun 20, 2026
6505aad
fix: use original logic for MemGetLabel for labeling_he_2014
william-silversmith Jun 20, 2026
23e9fd9
fix: use original MemGetLabel logic for labeling_sauf_background
william-silversmith Jun 20, 2026
0862d7b
perf: faster relabeling for sauf4c
william-silversmith Jun 22, 2026
e9c1829
revert: refactoring MemGetLabel in this way causes errors
william-silversmith Jun 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions include/labeling3D_PRED_2021.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,12 @@ class PRED_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (int s = 0; s < d; s++) {
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}

LabelsSolver::Dealloc(); // Memory deallocation of the labels solver

}
Expand Down Expand Up @@ -553,14 +549,10 @@ class PRED_3D : public Labeling3D<Connectivity3D::CONN_26> {
unsigned int h = img_.size.p[1];
unsigned int w = img_.size.p[2];

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step.p[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}
}
};
Expand Down
38 changes: 15 additions & 23 deletions include/labeling3D_PREDpp_2021.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,11 @@ class PREDpp_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (int s = 0; s < d; s++) {
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
}
const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}

LabelsSolver::Dealloc(); // Memory deallocation of the labels solver

Expand Down Expand Up @@ -566,21 +562,17 @@ class PREDpp_3D : public Labeling3D<Connectivity3D::CONN_26> {


void SecondScan() {
LabelsSolver::Flatten();
LabelsSolver::Flatten();

unsigned int d = img_.size.p[0];
unsigned int h = img_.size.p[1];
unsigned int w = img_.size.p[2];

unsigned int d = img_.size.p[0];
unsigned int h = img_.size.p[1];
unsigned int w = img_.size.p[2];

int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step.p[1] / sizeof(int);
}
}
const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}
}
};

Expand Down
20 changes: 6 additions & 14 deletions include/labeling3D_SAUF_2021.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,10 @@ class SAUF_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}

LabelsSolver::Dealloc(); // Memory deallocation of the labels solver
Expand Down Expand Up @@ -446,14 +442,10 @@ class SAUF_3D : public Labeling3D<Connectivity3D::CONN_26> {
unsigned int h = img_.size.p[1];
unsigned int w = img_.size.p[2];

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step.p[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}
}
};
Expand Down
20 changes: 6 additions & 14 deletions include/labeling3D_SAUFpp_2021.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,10 @@ class SAUFpp_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}

LabelsSolver::Dealloc(); // Memory deallocation of the labels solver
Expand Down Expand Up @@ -461,14 +457,10 @@ class SAUFpp_3D : public Labeling3D<Connectivity3D::CONN_26> {
unsigned int h = img_.size.p[1];
unsigned int w = img_.size.p[2];

const unsigned int voxels = h * w * d;
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (unsigned int s = 0; s < d; s++) {
for (unsigned int r = 0; r < h; r++) {
for (unsigned int c = 0; c < w; c++) {
img_row[c] = LabelsSolver::GetLabel(img_row[c]);
}
img_row += img_labels_.step.p[1] / sizeof(int);
}
for (unsigned int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}
}
};
Expand Down
20 changes: 6 additions & 14 deletions include/labeling3D_naive.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,10 @@ class naive_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

const int voxels = img_labels_.size[0] * img_labels_.size[1] * img_labels_.size[2];
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (int z = 0; z < img_labels_.size[0]; z++) {
for (int y = 0; y < img_labels_.size[1]; y++) {
for (int x = 0; x < img_labels_.size[2]; x++) {
img_row[x] = LabelsSolver::GetLabel(img_row[x]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
for (int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}

LabelsSolver::Dealloc(); // Memory deallocation of the labels solver
Expand Down Expand Up @@ -282,14 +278,10 @@ class naive_3D : public Labeling3D<Connectivity3D::CONN_26> {
// Second scan
LabelsSolver::Flatten();

const int voxels = img_labels_.size[0] * img_labels_.size[1] * img_labels_.size[2];
int * img_row = reinterpret_cast<int*>(img_labels_.data);
for (int z = 0; z < img_labels_.size[0]; z++) {
for (int y = 0; y < img_labels_.size[1]; y++) {
for (int x = 0; x < img_labels_.size[2]; x++) {
img_row[x] = LabelsSolver::GetLabel(img_row[x]);
}
img_row += img_labels_.step[1] / sizeof(int);
}
for (int i = 0; i < voxels; i++) {
img_row[i] = LabelsSolver::GetLabel(img_row[i]);
}
}
};
Expand Down
23 changes: 11 additions & 12 deletions include/labeling_PREDpp_2021.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ class PREDpp : public Labeling2D<Connectivity2D::CONN_8> {
// Second scan
n_labels_ = LabelsSolver::Flatten();

for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *b = img_labels_.ptr<unsigned int>(r_i);
unsigned int *e = b + img_labels_.cols;
for (; b != e; ++b) {
*b = LabelsSolver::GetLabel(*b);
}
const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}

LabelsSolver::Dealloc();
Expand Down Expand Up @@ -248,12 +246,13 @@ class PREDpp : public Labeling2D<Connectivity2D::CONN_8> {
// Second scan
n_labels_ = LabelsSolver::Flatten();

for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *b = img_labels_.ptr<unsigned int>(r_i);
unsigned int *e = b + img_labels_.cols;
for (; b != e; ++b) {
*b = LabelsSolver::GetLabel(*b);
}
const unsigned int w(img_.cols);
const unsigned int h(img_.rows);

const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/labeling_algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Labeling2D : public Labeling {

virtual ~Labeling2D() = default;

virtual std::string CheckAlg() const { return LabelingCheckSingleton2D::GetCheckAlg(Conn, LabelBackground); }
virtual std::string CheckAlg() const override { return LabelingCheckSingleton2D::GetCheckAlg(Conn, LabelBackground); }

virtual bool IsLabelBackground() const override { return LabelBackground; }

Expand All @@ -106,7 +106,7 @@ class Labeling3D : public Labeling {

virtual ~Labeling3D() = default;

virtual std::string CheckAlg() const { return LabelingCheckSingleton3D::GetCheckAlg(Conn, LabelBackground); }
virtual std::string CheckAlg() const override { return LabelingCheckSingleton3D::GetCheckAlg(Conn, LabelBackground); }

virtual bool IsLabelBackground() const override { return LabelBackground; }

Expand Down
23 changes: 11 additions & 12 deletions include/labeling_grana_2016.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ class PRED : public Labeling2D<Connectivity2D::CONN_8> {
// Second scan
n_labels_ = LabelsSolver::Flatten();

for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *b = img_labels_.ptr<unsigned int>(r_i);
unsigned int *e = b + img_labels_.cols;
for (; b != e; ++b) {
*b = LabelsSolver::GetLabel(*b);
}
const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}

LabelsSolver::Dealloc();
Expand Down Expand Up @@ -287,12 +285,13 @@ class PRED : public Labeling2D<Connectivity2D::CONN_8> {
// Second scan
n_labels_ = LabelsSolver::Flatten();

for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *b = img_labels_.ptr<unsigned int>(r_i);
unsigned int *e = b + img_labels_.cols;
for (; b != e; ++b) {
*b = LabelsSolver::GetLabel(*b);
}
const unsigned int w(img_.cols);
const unsigned int h(img_.rows);

const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}
}
};
Expand Down
26 changes: 11 additions & 15 deletions include/labeling_he_2008.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,10 @@ class RBTS : public Labeling2D<Connectivity2D::CONN_8>
n_labels_ = LabelsSolver::Flatten();

// Second scan
for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int* img_labels_row_start = img_labels_.ptr<unsigned int>(r_i);
unsigned int* img_labels_row_end = img_labels_row_start + img_labels_.cols;
unsigned int* img_labels_row = img_labels_row_start;
for (int c_i = 0; img_labels_row != img_labels_row_end; ++img_labels_row, ++c_i) {
*img_labels_row = LabelsSolver::GetLabel(*img_labels_row);
}
const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}

LabelsSolver::Dealloc();
Expand Down Expand Up @@ -465,14 +462,13 @@ class RBTS : public Labeling2D<Connectivity2D::CONN_8>
{
n_labels_ = LabelsSolver::Flatten();

// Second scan
for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int* img_labels_row_start = img_labels_.ptr<unsigned int>(r_i);
unsigned int* img_labels_row_end = img_labels_row_start + img_labels_.cols;
unsigned int* img_labels_row = img_labels_row_start;
for (int c_i = 0; img_labels_row != img_labels_row_end; ++img_labels_row, ++c_i) {
*img_labels_row = LabelsSolver::GetLabel(*img_labels_row);
}
const unsigned int w(img_.cols);
const unsigned int h(img_.rows);

const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}
}

Expand Down
30 changes: 13 additions & 17 deletions include/labeling_he_2014.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,10 @@ class CTB : public Labeling2D<Connectivity2D::CONN_8> {
n_labels_ = LabelsSolver::Flatten();

// Second scan
for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *img_labels_row_start = img_labels_.ptr<unsigned int>(r_i);
unsigned int *img_labels_row_end = img_labels_row_start + img_labels_.cols;
unsigned int *img_labels_row = img_labels_row_start;
for (int c_i = 0; img_labels_row != img_labels_row_end; ++img_labels_row, ++c_i) {
*img_labels_row = LabelsSolver::GetLabel(*img_labels_row);
}
const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}

LabelsSolver::Dealloc();
Expand Down Expand Up @@ -242,7 +239,7 @@ class CTB : public Labeling2D<Connectivity2D::CONN_8> {
img_labels(r_i,c_i) = LabelsSolver::MemGetLabel(img_labels(r_i, c_i));
}
}

// Store total accesses in the output vector 'accesses'
accesses = std::vector<uint64_t>((int)MD_SIZE, 0);

Expand Down Expand Up @@ -363,18 +360,17 @@ class CTB : public Labeling2D<Connectivity2D::CONN_8> {
#undef CONDITION_N4
#undef CONDITION_N5
}
void SecondScan()
void SecondScan()
{
n_labels_ = LabelsSolver::Flatten();

// Second scan
for (int r_i = 0; r_i < img_labels_.rows; ++r_i) {
unsigned int *img_labels_row_start = img_labels_.ptr<unsigned int>(r_i);
unsigned int *img_labels_row_end = img_labels_row_start + img_labels_.cols;
unsigned int *img_labels_row = img_labels_row_start;
for (int c_i = 0; img_labels_row != img_labels_row_end; ++img_labels_row, ++c_i) {
*img_labels_row = LabelsSolver::GetLabel(*img_labels_row);
}
const unsigned int w(img_.cols);
const unsigned int h(img_.rows);

const unsigned int pixels = h * w;
unsigned int * img_data = reinterpret_cast<unsigned int*>(img_labels_.data);
for (unsigned int i = 0; i < pixels; i++) {
img_data[i] = LabelsSolver::GetLabel(img_data[i]);
}
}
};
Expand Down
Loading