10
10
namespace cv {
11
11
namespace stMorph {
12
12
13
+ #pragma region decompKernel
14
+
13
15
// normalizeAnchor; Copied from filterengine.hpp.
14
16
static inline Point normalizeAnchor (Point anchor, Size ksize)
15
17
{
@@ -21,11 +23,6 @@ static inline Point normalizeAnchor(Point anchor, Size ksize)
21
23
return anchor;
22
24
}
23
25
24
- enum Op
25
- {
26
- Min, Max
27
- };
28
-
29
26
int log2 (int n)
30
27
{
31
28
int ans = -1 ;
@@ -97,7 +94,7 @@ std::vector<Point> findP2RectCorners(const Mat& stNode, int rowDepth, int colDep
97
94
if (row > 0 && stNode.at <uchar>(row - 1 , col) == 1
98
95
&& row + 1 < stNode.rows && stNode.at <uchar>(row + 1 , col) == 1 ) continue ;
99
96
100
- // ignore if neighboring block is white
97
+ // ignore if deeper cell is white
101
98
if (col + colOfst < stNode.cols && stNode.at <uchar>(row, col + colOfst) == 1 ) continue ;
102
99
if (col - colOfst >= 0 && stNode.at <uchar>(row, col - colOfst) == 1 ) continue ;
103
100
if (row + rowOfst < stNode.rows && stNode.at <uchar>(row + rowOfst, col) == 1 ) continue ;
@@ -143,15 +140,11 @@ std::vector<std::vector<std::vector<Point>>> genPow2RectsToCoverKernel(
143
140
return p2Rects;
144
141
}
145
142
143
+ /*
144
+ * Solves the rectilinear steiner arborescence problem greedy.
145
+ */
146
146
Mat SolveRSAPGreedy (const Mat& initialMap)
147
147
{
148
- /*
149
- * Solves the rectilinear steiner arborescence problem greedy.
150
- * https://link.springer.com/article/10.1007/BF01758762
151
- *
152
- * Following implementation is O(n^3)-time algorithm
153
- * which is different from the mothod proposed in the paper.
154
- */
155
148
CV_Assert (initialMap.type () == CV_8UC1);
156
149
std::vector<Point> pos;
157
150
for (int r = 0 ; r < initialMap.rows ; r++)
@@ -193,7 +186,7 @@ Mat SolveRSAPGreedy(const Mat& initialMap)
193
186
resMap.at <Vec2b>(row, maxX)[0 ] = 1 ;
194
187
195
188
pos[maxI] = Point (maxX, maxY);
196
- swap (pos[maxJ], pos[pos.size () - 1 ]);
189
+ std:: swap (pos[maxJ], pos[pos.size () - 1 ]);
197
190
pos.pop_back ();
198
191
}
199
192
return resMap;
@@ -202,13 +195,6 @@ Mat SolveRSAPGreedy(const Mat& initialMap)
202
195
Mat sparseTableFillPlanning (
203
196
std::vector<std::vector<std::vector<Point>>> pow2Rects, int rowDepthLim, int colDepthLim)
204
197
{
205
- /*
206
- * Plan the order to fill the required 2d-sparse-table nodes.
207
- * The type of returned mat is Vec2b.
208
- * if path[dr][dc][0] == 1 then st[dr+1][dc] will be calculated from st[dr][dc].
209
- * if path[dr][dc][1] == 1 then st[dr][dc+1] will be calculated from st[dr][dc].
210
- */
211
-
212
198
// list up required sparse table nodes.
213
199
Mat stMap = Mat::zeros (rowDepthLim, colDepthLim, CV_8UC1);
214
200
for (int rd = 0 ; rd < rowDepthLim; rd++)
@@ -234,9 +220,6 @@ kernelDecompInfo decompKernel(InputArray kernel, Point anchor, int iterations)
234
220
{
235
221
_kernel.at <uchar>(0 , 0 ) = 1 ;
236
222
}
237
- // Fix anchor to the center of the kernel.
238
- anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
239
-
240
223
241
224
int rowDepthLim = log2 (longestRowRunLength (_kernel)) + 1 ;
242
225
int colDepthLim = log2 (longestColRunLength (_kernel)) + 1 ;
@@ -246,11 +229,21 @@ kernelDecompInfo decompKernel(InputArray kernel, Point anchor, int iterations)
246
229
Mat stPlan
247
230
= sparseTableFillPlanning (pow2Rects, rowDepthLim, colDepthLim);
248
231
232
+ // Fix anchor to the center of the kernel.
249
233
anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
250
234
251
235
return { _kernel.rows , _kernel.cols , pow2Rects, stPlan, anchor, iterations };
252
236
}
253
237
238
+ #pragma endregion
239
+
240
+ #pragma region st-morphology
241
+
242
+ enum Op
243
+ {
244
+ Min, Max
245
+ };
246
+
254
247
void morphDfs (int minmax, Mat& st, Mat& dst,
255
248
std::vector<std::vector<std::vector<Point>>> row2Rects, const Mat& stPlan,
256
249
int rowDepth, int colDepth)
@@ -414,6 +407,10 @@ void morphologyEx(InputArray src, OutputArray dst, int op, kernelDecompInfo kdi,
414
407
}
415
408
}
416
409
410
+ #pragma endregion
411
+
412
+ #pragma region cv-morphology
413
+
417
414
void erode (InputArray src, OutputArray dst, InputArray kernel,
418
415
Point anchor, int iterations,
419
416
BorderTypes borderType, const Scalar& borderVal)
@@ -438,4 +435,6 @@ void morphologyEx(InputArray src, OutputArray dst, int op,
438
435
morphologyEx (src, dst, op, kdi, borderType, borderVal);
439
436
}
440
437
438
+ #pragma endregion
439
+
441
440
}} // cv::stMorph::
0 commit comments