Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8ca52b

Browse files
authored
Update thinning.cpp
1 parent66cf9b3 commitc8ca52b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

‎modules/ximgproc/src/thinning.cpp‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static uint8_t lut_guo_iter1[] = {
9292
1,1,1,1};
9393

9494
// Applies a thinning iteration to a binary image
95-
staticvoidthinningIteration(Mat &img, Mat &marker,constuint8_t*const lut) {
95+
staticvoidthinningIteration(Mat &img, Mat &marker,constuint8_t*const lut,bool &changed) {
9696
int rows = img.rows;
9797
int cols = img.cols;
9898

@@ -113,12 +113,20 @@ static void thinningIteration(Mat &img, Mat &marker, const uint8_t* const lut) {
113113
uchar p9 = imgRow[j - cols -1] !=0;
114114

115115
int neighbors = p9 | (p2 <<1) | (p3 <<2) | (p4 <<3) | (p5 <<4) | (p6 <<5) | (p7 <<6) | (p8 <<7);
116-
markerRow[j] = lut[neighbors];
116+
uchar lut_value = lut[neighbors];
117+
118+
if (lut_value ==0)
119+
{
120+
markerRow[j] = lut_value;
121+
changed =true;
122+
}
123+
117124
}
118125
}
119126
}
120127
});
121128

129+
// Bitwise AND and reset marker for the next iteration
122130
img &= marker;
123131
}
124132

@@ -138,15 +146,18 @@ void thinning(InputArray input, OutputArray output, int thinningType){
138146
constauto lutIter0 = (thinningType == THINNING_GUOHALL) ? lut_guo_iter0 : lut_zhang_iter0;
139147
constauto lutIter1 = (thinningType == THINNING_GUOHALL) ? lut_guo_iter1 : lut_zhang_iter1;
140148
do {
141-
thinningIteration(processed, marker, lutIter0);
142-
thinningIteration(processed, marker, lutIter1);
143-
constauto res =cv::norm(processed, prev, cv::NORM_L1);
144-
if (res <=0) {break; }
145-
processed.copyTo(prev);
149+
bool changed0 =false;
150+
bool changed1 =false;
151+
thinningIteration(processed, marker, lutIter0, changed0);
152+
thinningIteration(processed, marker, lutIter1, changed1);
153+
154+
if (changed0 | changed1)
155+
processed.copyTo(prev);
156+
else
157+
break;
146158
}while (true);
147159

148-
processed *=255;
149-
output.assign(processed);
160+
output.assign(processed *255);
150161
}
151162

152163
}//namespace ximgproc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp