1010namespace cv {
1111namespace stMorph {
1212
13+ #pragma region decompKernel
14+
1315// normalizeAnchor; Copied from filterengine.hpp.
1416static inline Point normalizeAnchor (Point anchor, Size ksize)
1517{
@@ -21,11 +23,6 @@ static inline Point normalizeAnchor(Point anchor, Size ksize)
2123 return anchor;
2224}
2325
24- enum Op
25- {
26- Min, Max
27- };
28-
2926int log2 (int n)
3027{
3128 int ans = -1 ;
@@ -97,7 +94,7 @@ std::vector<Point> findP2RectCorners(const Mat& stNode, int rowDepth, int colDep
9794 if (row > 0 && stNode.at <uchar>(row - 1 , col) == 1
9895 && row + 1 < stNode.rows && stNode.at <uchar>(row + 1 , col) == 1 ) continue ;
9996
100- // ignore if neighboring block is white
97+ // ignore if deeper cell is white
10198 if (col + colOfst < stNode.cols && stNode.at <uchar>(row, col + colOfst) == 1 ) continue ;
10299 if (col - colOfst >= 0 && stNode.at <uchar>(row, col - colOfst) == 1 ) continue ;
103100 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(
143140 return p2Rects;
144141}
145142
143+ /*
144+ * Solves the rectilinear steiner arborescence problem greedy.
145+ */
146146Mat SolveRSAPGreedy (const Mat& initialMap)
147147{
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- */
155148 CV_Assert (initialMap.type () == CV_8UC1);
156149 std::vector<Point> pos;
157150 for (int r = 0 ; r < initialMap.rows ; r++)
@@ -193,7 +186,7 @@ Mat SolveRSAPGreedy(const Mat& initialMap)
193186 resMap.at <Vec2b>(row, maxX)[0 ] = 1 ;
194187
195188 pos[maxI] = Point (maxX, maxY);
196- swap (pos[maxJ], pos[pos.size () - 1 ]);
189+ std:: swap (pos[maxJ], pos[pos.size () - 1 ]);
197190 pos.pop_back ();
198191 }
199192 return resMap;
@@ -202,13 +195,6 @@ Mat SolveRSAPGreedy(const Mat& initialMap)
202195Mat sparseTableFillPlanning (
203196 std::vector<std::vector<std::vector<Point>>> pow2Rects, int rowDepthLim, int colDepthLim)
204197{
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-
212198 // list up required sparse table nodes.
213199 Mat stMap = Mat::zeros (rowDepthLim, colDepthLim, CV_8UC1);
214200 for (int rd = 0 ; rd < rowDepthLim; rd++)
@@ -234,9 +220,6 @@ kernelDecompInfo decompKernel(InputArray kernel, Point anchor, int iterations)
234220 {
235221 _kernel.at <uchar>(0 , 0 ) = 1 ;
236222 }
237- // Fix anchor to the center of the kernel.
238- anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
239-
240223
241224 int rowDepthLim = log2 (longestRowRunLength (_kernel)) + 1 ;
242225 int colDepthLim = log2 (longestColRunLength (_kernel)) + 1 ;
@@ -246,11 +229,21 @@ kernelDecompInfo decompKernel(InputArray kernel, Point anchor, int iterations)
246229 Mat stPlan
247230 = sparseTableFillPlanning (pow2Rects, rowDepthLim, colDepthLim);
248231
232+ // Fix anchor to the center of the kernel.
249233 anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
250234
251235 return { _kernel.rows , _kernel.cols , pow2Rects, stPlan, anchor, iterations };
252236}
253237
238+ #pragma endregion
239+
240+ #pragma region st-morphology
241+
242+ enum Op
243+ {
244+ Min, Max
245+ };
246+
254247void morphDfs (int minmax, Mat& st, Mat& dst,
255248 std::vector<std::vector<std::vector<Point>>> row2Rects, const Mat& stPlan,
256249 int rowDepth, int colDepth)
@@ -414,6 +407,10 @@ void morphologyEx(InputArray src, OutputArray dst, int op, kernelDecompInfo kdi,
414407 }
415408}
416409
410+ #pragma endregion
411+
412+ #pragma region cv-morphology
413+
417414void erode (InputArray src, OutputArray dst, InputArray kernel,
418415 Point anchor, int iterations,
419416 BorderTypes borderType, const Scalar& borderVal)
@@ -438,4 +435,6 @@ void morphologyEx(InputArray src, OutputArray dst, int op,
438435 morphologyEx (src, dst, op, kdi, borderType, borderVal);
439436}
440437
438+ #pragma endregion
439+
441440}} // cv::stMorph::
0 commit comments