/work/install-coverage/include/opencv4/opencv2/imgproc/segmentation.hpp
Line | Count | Source (jump to first uncovered line) |
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_IMGPROC_SEGMENTATION_HPP |
6 | | #define OPENCV_IMGPROC_SEGMENTATION_HPP |
7 | | |
8 | | #include "opencv2/imgproc.hpp" |
9 | | |
10 | | namespace cv { |
11 | | |
12 | | namespace segmentation { |
13 | | |
14 | | //! @addtogroup imgproc_segmentation |
15 | | //! @{ |
16 | | |
17 | | |
18 | | /** @brief Intelligent Scissors image segmentation |
19 | | * |
20 | | * This class is used to find the path (contour) between two points |
21 | | * which can be used for image segmentation. |
22 | | * |
23 | | * Usage example: |
24 | | * @snippet snippets/imgproc_segmentation.cpp usage_example_intelligent_scissors |
25 | | * |
26 | | * Reference: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138.3811&rep=rep1&type=pdf">"Intelligent Scissors for Image Composition"</a> |
27 | | * algorithm designed by Eric N. Mortensen and William A. Barrett, Brigham Young University |
28 | | * @cite Mortensen95intelligentscissors |
29 | | */ |
30 | | class CV_EXPORTS_W_SIMPLE IntelligentScissorsMB |
31 | | { |
32 | | public: |
33 | | CV_WRAP |
34 | | IntelligentScissorsMB(); |
35 | | |
36 | | /** @brief Specify weights of feature functions |
37 | | * |
38 | | * Consider keeping weights normalized (sum of weights equals to 1.0) |
39 | | * Discrete dynamic programming (DP) goal is minimization of costs between pixels. |
40 | | * |
41 | | * @param weight_non_edge Specify cost of non-edge pixels (default: 0.43f) |
42 | | * @param weight_gradient_direction Specify cost of gradient direction function (default: 0.43f) |
43 | | * @param weight_gradient_magnitude Specify cost of gradient magnitude function (default: 0.14f) |
44 | | */ |
45 | | CV_WRAP |
46 | | IntelligentScissorsMB& setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude); |
47 | | |
48 | | /** @brief Specify gradient magnitude max value threshold |
49 | | * |
50 | | * Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article). |
51 | | * Otherwize pixels with `gradient magnitude >= threshold` have zero cost. |
52 | | * |
53 | | * @note Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos). |
54 | | * |
55 | | * @param gradient_magnitude_threshold_max Specify gradient magnitude max value threshold (default: 0, disabled) |
56 | | */ |
57 | | CV_WRAP |
58 | | IntelligentScissorsMB& setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max = 0.0f); |
59 | | |
60 | | /** @brief Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters |
61 | | * |
62 | | * This feature extractor is used by default according to article. |
63 | | * |
64 | | * Implementation has additional filtering for regions with low-amplitude noise. |
65 | | * This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16). |
66 | | * |
67 | | * @note Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first). |
68 | | * |
69 | | * @note Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters(). |
70 | | * |
71 | | * @param gradient_magnitude_min_value Minimal gradient magnitude value for edge pixels (default: 0, check is disabled) |
72 | | */ |
73 | | CV_WRAP |
74 | | IntelligentScissorsMB& setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value = 0.0f); |
75 | | |
76 | | /** @brief Switch edge feature extractor to use Canny edge detector |
77 | | * |
78 | | * @note "Laplacian Zero-Crossing" feature extractor is used by default (following to original article) |
79 | | * |
80 | | * @sa Canny |
81 | | */ |
82 | | CV_WRAP |
83 | | IntelligentScissorsMB& setEdgeFeatureCannyParameters( |
84 | | double threshold1, double threshold2, |
85 | | int apertureSize = 3, bool L2gradient = false |
86 | | ); |
87 | | |
88 | | /** @brief Specify input image and extract image features |
89 | | * |
90 | | * @param image input image. Type is #CV_8UC1 / #CV_8UC3 |
91 | | */ |
92 | | CV_WRAP |
93 | | IntelligentScissorsMB& applyImage(InputArray image); |
94 | | |
95 | | /** @brief Specify custom features of input image |
96 | | * |
97 | | * Customized advanced variant of applyImage() call. |
98 | | * |
99 | | * @param non_edge Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are `{0, 1}`. |
100 | | * @param gradient_direction Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: `x^2 + y^2 == 1` |
101 | | * @param gradient_magnitude Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range `[0, 1]`. |
102 | | * @param image **Optional parameter**. Must be specified if subset of features is specified (non-specified features are calculated internally) |
103 | | */ |
104 | | CV_WRAP |
105 | | IntelligentScissorsMB& applyImageFeatures( |
106 | | InputArray non_edge, InputArray gradient_direction, InputArray gradient_magnitude, |
107 | | InputArray image = noArray() |
108 | | ); |
109 | | |
110 | | /** @brief Prepares a map of optimal paths for the given source point on the image |
111 | | * |
112 | | * @note applyImage() / applyImageFeatures() must be called before this call |
113 | | * |
114 | | * @param sourcePt The source point used to find the paths |
115 | | */ |
116 | | CV_WRAP void buildMap(const Point& sourcePt); |
117 | | |
118 | | /** @brief Extracts optimal contour for the given target point on the image |
119 | | * |
120 | | * @note buildMap() must be called before this call |
121 | | * |
122 | | * @param targetPt The target point |
123 | | * @param[out] contour The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with `std::vector<Point>`) |
124 | | * @param backward Flag to indicate reverse order of retrived pixels (use "true" value to fetch points from the target to the source point) |
125 | | */ |
126 | | CV_WRAP void getContour(const Point& targetPt, OutputArray contour, bool backward = false) const; |
127 | | |
128 | | #ifndef CV_DOXYGEN |
129 | | struct Impl; |
130 | 0 | inline Impl* getImpl() const { return impl.get(); } |
131 | | protected: |
132 | | std::shared_ptr<Impl> impl; |
133 | | #endif |
134 | | }; |
135 | | |
136 | | //! @} |
137 | | |
138 | | } // namespace segmentation |
139 | | } // namespace cv |
140 | | |
141 | | #endif // OPENCV_IMGPROC_SEGMENTATION_HPP |