Skip to content

Commit

Permalink
Update thinning.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sturkmen72 authored Oct 2, 2024
1 parent b338f6c commit 6965db1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions modules/ximgproc/src/thinning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ static void thinningIteration(Mat &img, Mat &marker, const uint8_t* const lut) {
marker.row(0).setTo(1);
marker.row(rows - 1).setTo(1);

marker.forEach<uchar>([=](uchar& value, const int postion[]) {
int i = postion[0];
int j = postion[1];
marker.forEach<uchar>([=](uchar& value, const int position[]) {
int i = position[0];
int j = position[1];
if (i == 0 || j == 0 || i == rows - 1 || j == cols - 1) { return; }

auto ptr = img.ptr(i, j); // p1
if (ptr[0]) {
uchar p2 = ptr[-cols];
uchar p3 = ptr[-cols + 1];
uchar p4 = ptr[1];
uchar p5 = ptr[cols + 1];
uchar p6 = ptr[cols];
uchar p7 = ptr[cols - 1];
uchar p8 = ptr[-1];
uchar p9 = ptr[-cols - 1];
uchar p2 = ptr[-cols] != 0;
uchar p3 = ptr[-cols + 1] != 0;
uchar p4 = ptr[1] != 0;
uchar p5 = ptr[cols + 1] != 0;
uchar p6 = ptr[cols] != 0;
uchar p7 = ptr[cols - 1] != 0;
uchar p8 = ptr[-1] != 0;
uchar p9 = ptr[-cols - 1] != 0;

int neighbors = p9 | (p2 << 1) | (p3 << 2) | (p4 << 3) | (p5 << 4) | (p6 << 5) | (p7 << 6) | (p8 << 7);
value = lut[neighbors];
Expand Down

0 comments on commit 6965db1

Please sign in to comment.