Skip to content

Commit 73143df

Browse files
committed
最初のコミット
2 parents acd145f + 4f73f88 commit 73143df

File tree

5 files changed

+1162
-0
lines changed

5 files changed

+1162
-0
lines changed

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "ximgproc/color_match.hpp"
6464
#include "ximgproc/radon_transform.hpp"
6565
#include "ximgproc/find_ellipses.hpp"
66+
#include "ximgproc/sparse_table_morphology.hpp"
6667

6768

6869
/**
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef __OPENCV_SPARSE_TABLE_MORPHOLOGY_HPP__
6+
#define __OPENCV_SPARSE_TABLE_MORPHOLOGY_HPP__
7+
8+
#include <opencv2/core.hpp>
9+
#include <vector>
10+
11+
namespace cv {
12+
namespace stMorph {
13+
14+
//! @addtogroup imgproc_filter
15+
//! @{
16+
17+
/**
18+
* @struct kernelDecompInfo
19+
* @brief struct to hold the results of decomposing the structuring element.
20+
*/
21+
typedef struct _kernelDecompInfo
22+
{
23+
//! rows of the original kernel.
24+
int rows;
25+
//! cols of the original kernel.
26+
int cols;
27+
//!
28+
//! set of rectangles to covers the kernel which height and width both are power of 2.
29+
//! point stRects[rd][cd](c,r) means a rectangle left-top (c,r), width 2^rd and height 2^cd.
30+
//!
31+
std::vector<std::vector<std::vector<Point>>> stRects;
32+
//!
33+
//! Vec2b Mat which sotres the order to calculate sparse table.
34+
//! The type of returned mat is Vec2b.
35+
//! * if path[dr][dc][0] == 1 then st[dr+1][dc] will be calculated from st[dr][dc].
36+
//! * if path[dr][dc][1] == 1 then st[dr][dc+1] will be calculated from st[dr][dc].
37+
//!
38+
Mat plan;
39+
//! anchor position of the kernel.
40+
Point anchor;
41+
//! Number of times erosion and dilation are applied.
42+
int iterations;
43+
} kernelDecompInfo;
44+
45+
/**
46+
* @brief Decompose the structuring element.
47+
*
48+
* @param kernel structuring element used for subsequent morphological operations.
49+
* @param anchor position of the anchor within the element.
50+
* default value (-1, -1) means that the anchor is at the element center.
51+
* @param iterations number of times is applied.
52+
*/
53+
CV_EXPORTS_W kernelDecompInfo decompKernel(InputArray kernel,
54+
Point anchor = Point(-1, -1), int iterations = 1);
55+
56+
/**
57+
* @brief Erodes an image with a kernelDecompInfo using spase table method.
58+
*
59+
* @param src input image
60+
* @param dst output image of the same size and type as src.
61+
* @param kdi pre-computated kernelDecompInfo structure.
62+
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
63+
* @param borderValue border value in case of a constant border
64+
*/
65+
CV_EXPORTS_W void erode( InputArray src, OutputArray dst, kernelDecompInfo kdi,
66+
BorderTypes borderType = BORDER_CONSTANT,
67+
const Scalar& borderValue = morphologyDefaultBorderValue() );
68+
69+
/**
70+
* @brief Dilates an image with a kernelDecompInfo using spase table method.
71+
*
72+
* @param src input image;
73+
* @param dst output image of the same size and type as src.
74+
* @param kdi pre-computated kernelDecompInfo structure.
75+
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
76+
* @param borderValue border value in case of a constant border
77+
*/
78+
CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, kernelDecompInfo kdi,
79+
BorderTypes borderType = BORDER_CONSTANT,
80+
const Scalar& borderValue = morphologyDefaultBorderValue() );
81+
82+
/**
83+
* @brief Performs advanced morphological transformations with a kernelDecompInfo.
84+
*
85+
* @param src input image;
86+
* @param dst output image of the same size and type as src.
87+
* @param op all operations supported by cv::morphologyEx (except cv::MORPH_HITMISS)
88+
* @param kdi pre-computated kernelDecompInfo structure.
89+
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
90+
* @param borderValue border value in case of a constant border
91+
*/
92+
CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, int op, kernelDecompInfo kdi,
93+
BorderTypes borderType = BORDER_CONSTANT,
94+
const Scalar& borderValue = morphologyDefaultBorderValue() );
95+
96+
/**
97+
* @brief Faster implementation of cv::erode with sparse table concept.
98+
*
99+
* @param src input image; the number of channels can be arbitrary, but the depth should be one of
100+
* CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
101+
* @param dst output image of the same size and type as src.
102+
* @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
103+
* structuring element is used. Kernel can be created using #getStructuringElement.
104+
* @param anchor position of the anchor within the element; default value (-1, -1) means that the
105+
* anchor is at the element center.
106+
* @param iterations number of times erosion is applied.
107+
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
108+
* @param borderValue border value in case of a constant border
109+
*
110+
* @see cv::erode
111+
*/
112+
CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
113+
Point anchor = Point(-1,-1), int iterations = 1,
114+
BorderTypes borderType = BORDER_CONSTANT,
115+
const Scalar& borderValue = morphologyDefaultBorderValue() );
116+
117+
/**
118+
* @brief Faster implementation of cv::dilate with sparse table concept.
119+
*
120+
* @param src input image; the number of channels can be arbitrary, but the depth should be one of
121+
* CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
122+
* @param dst output image of the same size and type as src.
123+
* @param kernel structuring element used for dilation; if element=Mat(), a 3 x 3 rectangular
124+
* structuring element is used. Kernel can be created using #getStructuringElement
125+
* @param anchor position of the anchor within the element; default value (-1, -1) means that the
126+
* anchor is at the element center.
127+
* @param iterations number of times dilation is applied.
128+
* @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not suported.
129+
* @param borderValue border value in case of a constant border
130+
*
131+
* @see cv::dilate
132+
*/
133+
CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
134+
Point anchor = Point(-1,-1), int iterations = 1,
135+
BorderTypes borderType = BORDER_CONSTANT,
136+
const Scalar& borderValue = morphologyDefaultBorderValue() );
137+
138+
/**
139+
* @brief Faster implementation of cv::morphologyEx with sparse table concept.
140+
141+
* @param src Source image. The number of channels can be arbitrary. The depth should be one of
142+
* CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
143+
* @param dst Destination image of the same size and type as source image.
144+
* @param op Type of a morphological operation, see #MorphTypes
145+
* @param kernel Structuring element. It can be created using #getStructuringElement.
146+
* @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the
147+
* kernel center.
148+
* @param iterations Number of times erosion and dilation are applied.
149+
* @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
150+
* @param borderValue Border value in case of a constant border. The default value has a special
151+
* meaning.
152+
* @note The number of iterations is the number of times erosion or dilatation operation will be applied.
153+
* For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply
154+
* successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate).
155+
*
156+
* @see cv::morphologyEx
157+
*/
158+
CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
159+
int op, InputArray kernel,
160+
Point anchor = Point(-1,-1), int iterations = 1,
161+
BorderTypes borderType = BORDER_CONSTANT,
162+
const Scalar& borderValue = morphologyDefaultBorderValue() );
163+
//! @}
164+
165+
}} // cv::stMorph::
166+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "perf_precomp.hpp"
6+
7+
namespace opencv_test {
8+
namespace {
9+
10+
typedef tuple<MorphTypes, MorphShapes> MorphTypes_MorphShapes_t;
11+
typedef TestBaseWithParam<MorphTypes_MorphShapes_t> SparseTableMorphologyPerfTest;
12+
13+
PERF_TEST_P(SparseTableMorphologyPerfTest, perf,
14+
testing::Combine(
15+
testing::Values(
16+
MORPH_ERODE, MORPH_DILATE, MORPH_OPEN, MORPH_CLOSE,
17+
MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT),
18+
testing::Values(MORPH_RECT, MORPH_CROSS, MORPH_ELLIPSE)
19+
) )
20+
{
21+
MorphTypes_MorphShapes_t params = GetParam();
22+
int seSize = 51;
23+
Size sz = sz1080p;
24+
MorphTypes op = std::tr1::get<0>(params);
25+
MorphShapes knType = std::tr1::get<1>(params);
26+
27+
Mat src(sz, CV_8UC3), dst(sz, CV_8UC3);
28+
Mat kernel = getStructuringElement(knType, cv::Size(2 * seSize + 1, 2 * seSize + 1));
29+
30+
declare.in(src, WARMUP_RNG).out(dst);
31+
32+
TEST_CYCLE_N(5)
33+
{
34+
cv::stMorph::morphologyEx(src, dst, op, kernel);
35+
}
36+
37+
SANITY_CHECK_NOTHING();
38+
}
39+
40+
}} // opencv_test:: ::

0 commit comments

Comments
 (0)