Skip to content

Commit 2db05d6

Browse files
committed
スタイルガイドに合わせて行の長さ、名前空間など修正
1 parent 315da17 commit 2db05d6

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

modules/ximgproc/include/opencv2/ximgproc/sparse_table_morphology.hpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <vector>
1010

1111
namespace cv {
12-
namespace ximgproc {
1312
namespace stMorph {
1413

1514
//! @addtogroup imgproc_filter
@@ -25,13 +24,16 @@ namespace stMorph {
2524
* structuring element is used. Kernel can be created using #getStructuringElement.
2625
* @param anchor position of the anchor within the element; default value (-1, -1) means that the
2726
* anchor is at the element center.
27+
* @param iterations number of times erosion is applied.
2828
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
2929
* @param borderValue border value in case of a constant border
3030
*
3131
* @see cv::erode
3232
*/
33-
CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, Point anchor = Point(-1,-1),
34-
int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() );
33+
CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
34+
Point anchor = Point(-1,-1), int iterations = 1,
35+
int borderType = BORDER_CONSTANT,
36+
const Scalar& borderValue = morphologyDefaultBorderValue() );
3537

3638
/**
3739
* @brief Faster implementation of cv::dilate with sparse table concept.
@@ -43,13 +45,16 @@ CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, Poi
4345
* structuring element is used. Kernel can be created using #getStructuringElement
4446
* @param anchor position of the anchor within the element; default value (-1, -1) means that the
4547
* anchor is at the element center.
48+
* @param iterations number of times dilation is applied.
4649
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not suported.
4750
* @param borderValue border value in case of a constant border
4851
*
4952
* @see cv::dilate
5053
*/
51-
CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel, Point anchor = Point(-1, -1),
52-
int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() );
54+
CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
55+
Point anchor = Point(-1,-1), int iterations = 1,
56+
int borderType = BORDER_CONSTANT,
57+
const Scalar& borderValue = morphologyDefaultBorderValue() );
5358

5459
/**
5560
* @brief Faster implementation of cv::morphologyEx with sparse table concept.
@@ -71,9 +76,11 @@ CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel, Po
7176
*
7277
* @see cv::morphologyEx
7378
*/
74-
CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor = Point(-1,-1),
75-
int iterations = 1,
76-
int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() );
79+
CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
80+
int op, InputArray kernel,
81+
Point anchor = Point(-1,-1), int iterations = 1,
82+
int borderType = BORDER_CONSTANT,
83+
const Scalar& borderValue = morphologyDefaultBorderValue() );
7784

7885
//! @}
7986

@@ -119,10 +126,8 @@ CV_EXPORTS_W std::vector<Rect> genPow2RectsToCoverKernel(InputArray kernel);
119126
///*
120127
//* Plan the order to calculate the sparse table nodes.
121128
//*/
122-
CV_EXPORTS_W std::vector<StStep> planSparseTableConstruction(std::vector<std::vector<bool>> requiredSparseTableNodeMap);
129+
CV_EXPORTS_W std::vector<StStep> planSparseTableConstr(std::vector<std::vector<bool>> stNodeMap);
123130

124-
} // namespace st
125-
} // namespace ximgproc
126-
} // namespace cv
131+
}} // cv::stMorph::
127132

128133
#endif

modules/ximgproc/src/sparse_table_morphology.cpp

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111

1212
namespace cv {
13-
namespace ximgproc {
1413
namespace stMorph {
1514

1615
std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
@@ -20,7 +19,7 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
2019
Mat kernel = _kernel.getMat();
2120

2221
// generate log2 table
23-
int len = max(kernel.rows, kernel.cols) + 1;
22+
int len = std::max(kernel.rows, kernel.cols) + 1;
2423
std::vector<int> log2(len);
2524
for (int i = 2; i < len; i++) log2[i] = log2[i >> 1] + 1;
2625

@@ -103,8 +102,10 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
103102
if (ptr[0] == 0) continue;
104103

105104
// ignore if both sides are white by each axis
106-
if (col > 0 && ptr[-1] == 1 && col < colLim && ptr[1] == 1) continue;
107-
if (row > 0 && ptr[-kernel.cols] && row < rowLim && ptr[kernel.cols] == 1) continue;
105+
if (col > 0 && ptr[-1] == 1
106+
&& col < colLim && ptr[1] == 1) continue;
107+
if (row > 0 && ptr[-kernel.cols]
108+
&& row < rowLim && ptr[kernel.cols] == 1) continue;
108109

109110
// ignore one of neighbor block is white; will be alive in deeper table
110111
if (col + colOfst <= colLim && ptr[colOfst] == 1) continue;
@@ -122,7 +123,7 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
122123
return p2Rects;
123124
}
124125

125-
std::vector<StStep> planSparseTableConstruction(std::vector<std::vector<bool>> sparseMatMap)
126+
std::vector<StStep> planSparseTableConstr(std::vector<std::vector<bool>> sparseMatMap)
126127
{
127128
/*
128129
*
@@ -150,8 +151,8 @@ std::vector<StStep> planSparseTableConstruction(std::vector<std::vector<bool>> s
150151
{
151152
for (int j = i + 1; j < pos.size(); j++)
152153
{
153-
int _x = min(pos[i].x, pos[j].x);
154-
int _y = min(pos[i].y, pos[j].y);
154+
int _x = std::min(pos[i].x, pos[j].x);
155+
int _y = std::min(pos[i].y, pos[j].y);
155156
int cost = _x + _y;
156157
if (maxCost < cost)
157158
{
@@ -163,17 +164,21 @@ std::vector<StStep> planSparseTableConstruction(std::vector<std::vector<bool>> s
163164
}
164165
}
165166
}
166-
for (int col = pos[maxI].x - 1; col >= maxX; col--) plan.emplace_back(pos[maxI].y, col, Dim::Col);
167-
for (int row = pos[maxI].y - 1; row >= maxY; row--) plan.emplace_back(row, maxX, Dim::Row);
168-
for (int col = pos[maxJ].x - 1; col >= maxX; col--) plan.emplace_back(pos[maxJ].y, col, Dim::Col);
169-
for (int row = pos[maxJ].y - 1; row >= maxY; row--) plan.emplace_back(row, maxX, Dim::Row);
167+
for (int col = pos[maxI].x - 1; col >= maxX; col--)
168+
plan.emplace_back(pos[maxI].y, col, Dim::Col);
169+
for (int row = pos[maxI].y - 1; row >= maxY; row--)
170+
plan.emplace_back(row, maxX, Dim::Row);
171+
for (int col = pos[maxJ].x - 1; col >= maxX; col--)
172+
plan.emplace_back(pos[maxJ].y, col, Dim::Col);
173+
for (int row = pos[maxJ].y - 1; row >= maxY; row--)
174+
plan.emplace_back(row, maxX, Dim::Row);
170175

171176
pos[maxI] = Point(maxX, maxY);
172-
std::swap(pos[maxJ], pos[pos.size() - 1]);
177+
swap(pos[maxJ], pos[pos.size() - 1]);
173178
pos.pop_back();
174179
}
175180

176-
std::reverse(plan.begin(), plan.end());
181+
reverse(plan.begin(), plan.end());
177182
return plan;
178183
}
179184

@@ -195,7 +200,7 @@ void makeMinSparseTableMat(InputArray src, OutputArray dst, int rowStep, int col
195200
{
196201
for (int colCh = 0; colCh < colChLim; colCh++)
197202
{
198-
// Somehow min(a,b) or a<b?a:b are slower.
203+
// Somehow std::min(a,b) or a<b?a:b are slower.
199204
if (*srcPtr1 < *srcPtr2)
200205
{
201206
*dstPtr++ = *srcPtr1++;
@@ -247,12 +252,14 @@ void makeMaxSparseTableMat(InputArray src, OutputArray dst, int rowStep, int col
247252
}
248253
}
249254

250-
void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor,
255+
void dilate(InputArray src, OutputArray dst, InputArray kernel,
256+
Point anchor, int iterations,
251257
int borderType, const Scalar& borderValue)
252258
{
253259
}
254260

255-
void erode(InputArray _src, OutputArray _dst, InputArray _kernel, Point anchor,
261+
void erode(InputArray _src, OutputArray _dst, InputArray _kernel,
262+
Point anchor, int iterations,
256263
int borderType, const Scalar& borderValue)
257264
{
258265
uchar ZERO = 255;
@@ -262,7 +269,7 @@ void erode(InputArray _src, OutputArray _dst, InputArray _kernel, Point anchor,
262269
anchor = stMorph::normalizeAnchor(anchor, kernel.size());
263270

264271
Scalar bV = borderValue;
265-
if (borderType == cv::BorderTypes::BORDER_CONSTANT && borderValue == cv::morphologyDefaultBorderValue())
272+
if (borderType == BorderTypes::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue())
266273
{
267274
bV = Scalar::all(ZERO);
268275
// see morph.dispatch.cpp:111
@@ -285,14 +292,18 @@ void erode(InputArray _src, OutputArray _dst, InputArray _kernel, Point anchor,
285292

286293
// list up required sparse table nodes.
287294
std::vector<std::vector<bool>> sparseMatMap(rowDepthLim, std::vector<bool>(colDepthLim, false));
288-
for (int i = 0; i < pow2Rects.size(); i++) sparseMatMap[pow2Rects[i].height][pow2Rects[i].width] = true;
295+
for (int i = 0; i < pow2Rects.size(); i++)
296+
sparseMatMap[pow2Rects[i].height][pow2Rects[i].width] = true;
289297

290298
// plan how to calculate required nodes of 2D sparse table.
291-
std::vector<StStep> stPlan = planSparseTableConstruction(sparseMatMap);
299+
std::vector<StStep> stPlan = planSparseTableConstr(sparseMatMap);
292300

293301
// adding border to the source.
294302
Mat expandedSrc(src.rows + kernel.rows, src.cols + kernel.cols, src.type());
295-
cv::copyMakeBorder(src, expandedSrc, anchor.y, kernel.cols - 1 - anchor.y, anchor.x, kernel.rows - 1 - anchor.x, borderType, bV);
303+
copyMakeBorder(src, expandedSrc,
304+
anchor.y, kernel.cols - 1 - anchor.y,
305+
anchor.x, kernel.rows - 1 - anchor.x,
306+
borderType, bV);
296307

297308
// calculate sparse table nodes
298309
std::vector<std::vector<Mat>> st(rowDepthLim, std::vector<Mat>(colDepthLim));
@@ -303,10 +314,12 @@ void erode(InputArray _src, OutputArray _dst, InputArray _kernel, Point anchor,
303314
switch (step.ax)
304315
{
305316
case Dim::Col:
306-
makeMinSparseTableMat(st[step.dimRow][step.dimCol], st[step.dimRow][step.dimCol + 1], 0, 1 << step.dimCol);
317+
makeMinSparseTableMat(st[step.dimRow][step.dimCol], st[step.dimRow][step.dimCol + 1],
318+
0, 1 << step.dimCol);
307319
break;
308320
case Dim::Row:
309-
makeMinSparseTableMat(st[step.dimRow][step.dimCol], st[step.dimRow + 1][step.dimCol], 1 << step.dimRow, 0);
321+
makeMinSparseTableMat(st[step.dimRow][step.dimCol], st[step.dimRow + 1][step.dimCol],
322+
1 << step.dimRow, 0);
310323
break;
311324
}
312325
}
@@ -342,6 +355,4 @@ void morphologyEx(InputArray _src, OutputArray _dst, int op,
342355
{
343356
}
344357

345-
} // namespace st
346-
} // namespace ximgproc
347-
} // namespace cv
358+
}} // cv::st::

0 commit comments

Comments
 (0)