1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Third party copyrights are property of their respective owners. 16 // 17 // Redistribution and use in source and binary forms, with or without modification, 18 // are permitted provided that the following conditions are met: 19 // 20 // * Redistribution's of source code must retain the above copyright notice, 21 // this list of conditions and the following disclaimer. 22 // 23 // * Redistribution's in binary form must reproduce the above copyright notice, 24 // this list of conditions and the following disclaimer in the documentation 25 // and/or other materials provided with the distribution. 26 // 27 // * The name of the copyright holders may not be used to endorse or promote products 28 // derived from this software without specific prior written permission. 29 // 30 // This software is provided by the copyright holders and contributors "as is" and 31 // any express or implied warranties, including, but not limited to, the implied 32 // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 // In no event shall the Intel Corporation or contributors be liable for any direct, 34 // indirect, incidental, special, exemplary, or consequential damages 35 // (including, but not limited to, procurement of substitute goods or services; 36 // loss of use, data, or profits; or business interruption) however caused 37 // and on any theory of liability, whether in contract, strict liability, 38 // or tort (including negligence or otherwise) arising in any way out of 39 // the use of this software, even if advised of the possibility of such damage. 40 // 41 //M*/ 42 43 #ifndef __OPENCV_CUDAFILTERS_HPP__ 44 #define __OPENCV_CUDAFILTERS_HPP__ 45 46 #ifndef __cplusplus 47 # error cudafilters.hpp header must be compiled as C++ 48 #endif 49 50 #include "opencv2/core/cuda.hpp" 51 #include "opencv2/imgproc.hpp" 52 53 /** 54 @addtogroup cuda 55 @{ 56 @defgroup cudafilters Image Filtering 57 58 Functions and classes described in this section are used to perform various linear or non-linear 59 filtering operations on 2D images. 60 61 @note 62 - An example containing all basic morphology operators like erode and dilate can be found at 63 opencv_source_code/samples/gpu/morphology.cpp 64 65 @} 66 */ 67 68 namespace cv { namespace cuda { 69 70 //! @addtogroup cudafilters 71 //! @{ 72 73 /** @brief Common interface for all CUDA filters : 74 */ 75 class CV_EXPORTS Filter : public Algorithm 76 { 77 public: 78 /** @brief Applies the specified filter to the image. 79 80 @param src Input image. 81 @param dst Output image. 82 @param stream Stream for the asynchronous version. 83 */ 84 virtual void apply(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0; 85 }; 86 87 //////////////////////////////////////////////////////////////////////////////////////////////////// 88 // Box Filter 89 90 /** @brief Creates a normalized 2D box filter. 91 92 @param srcType Input image type. Only CV_8UC1 and CV_8UC4 are supported for now. 93 @param dstType Output image type. Only the same type as src is supported for now. 94 @param ksize Kernel size. 95 @param anchor Anchor point. The default value Point(-1, -1) means that the anchor is at the kernel 96 center. 97 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 98 @param borderVal Default border value. 99 100 @sa boxFilter 101 */ 102 CV_EXPORTS Ptr<Filter> createBoxFilter(int srcType, int dstType, Size ksize, Point anchor = Point(-1,-1), 103 int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 104 105 //////////////////////////////////////////////////////////////////////////////////////////////////// 106 // Linear Filter 107 108 /** @brief Creates a non-separable linear 2D filter. 109 110 @param srcType Input image type. Supports CV_8U , CV_16U and CV_32F one and four channel image. 111 @param dstType Output image type. Only the same type as src is supported for now. 112 @param kernel 2D array of filter coefficients. 113 @param anchor Anchor point. The default value Point(-1, -1) means that the anchor is at the kernel 114 center. 115 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 116 @param borderVal Default border value. 117 118 @sa filter2D 119 */ 120 CV_EXPORTS Ptr<Filter> createLinearFilter(int srcType, int dstType, InputArray kernel, Point anchor = Point(-1,-1), 121 int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 122 123 //////////////////////////////////////////////////////////////////////////////////////////////////// 124 // Laplacian Filter 125 126 /** @brief Creates a Laplacian operator. 127 128 @param srcType Input image type. Supports CV_8U , CV_16U and CV_32F one and four channel image. 129 @param dstType Output image type. Only the same type as src is supported for now. 130 @param ksize Aperture size used to compute the second-derivative filters (see getDerivKernels). It 131 must be positive and odd. Only ksize = 1 and ksize = 3 are supported. 132 @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is 133 applied (see getDerivKernels ). 134 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 135 @param borderVal Default border value. 136 137 @sa Laplacian 138 */ 139 CV_EXPORTS Ptr<Filter> createLaplacianFilter(int srcType, int dstType, int ksize = 1, double scale = 1, 140 int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 141 142 //////////////////////////////////////////////////////////////////////////////////////////////////// 143 // Separable Linear Filter 144 145 /** @brief Creates a separable linear filter. 146 147 @param srcType Source array type. 148 @param dstType Destination array type. 149 @param rowKernel Horizontal filter coefficients. Support kernels with size \<= 32 . 150 @param columnKernel Vertical filter coefficients. Support kernels with size \<= 32 . 151 @param anchor Anchor position within the kernel. Negative values mean that anchor is positioned at 152 the aperture center. 153 @param rowBorderMode Pixel extrapolation method in the vertical direction For details, see 154 borderInterpolate. 155 @param columnBorderMode Pixel extrapolation method in the horizontal direction. 156 157 @sa sepFilter2D 158 */ 159 CV_EXPORTS Ptr<Filter> createSeparableLinearFilter(int srcType, int dstType, InputArray rowKernel, InputArray columnKernel, 160 Point anchor = Point(-1,-1), int rowBorderMode = BORDER_DEFAULT, int columnBorderMode = -1); 161 162 //////////////////////////////////////////////////////////////////////////////////////////////////// 163 // Deriv Filter 164 165 /** @brief Creates a generalized Deriv operator. 166 167 @param srcType Source image type. 168 @param dstType Destination array type. 169 @param dx Derivative order in respect of x. 170 @param dy Derivative order in respect of y. 171 @param ksize Aperture size. See getDerivKernels for details. 172 @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not. 173 See getDerivKernels for details. 174 @param scale Optional scale factor for the computed derivative values. By default, no scaling is 175 applied. For details, see getDerivKernels . 176 @param rowBorderMode Pixel extrapolation method in the vertical direction. For details, see 177 borderInterpolate. 178 @param columnBorderMode Pixel extrapolation method in the horizontal direction. 179 */ 180 CV_EXPORTS Ptr<Filter> createDerivFilter(int srcType, int dstType, int dx, int dy, 181 int ksize, bool normalize = false, double scale = 1, 182 int rowBorderMode = BORDER_DEFAULT, int columnBorderMode = -1); 183 184 /** @brief Creates a Sobel operator. 185 186 @param srcType Source image type. 187 @param dstType Destination array type. 188 @param dx Derivative order in respect of x. 189 @param dy Derivative order in respect of y. 190 @param ksize Size of the extended Sobel kernel. Possible values are 1, 3, 5 or 7. 191 @param scale Optional scale factor for the computed derivative values. By default, no scaling is 192 applied. For details, see getDerivKernels . 193 @param rowBorderMode Pixel extrapolation method in the vertical direction. For details, see 194 borderInterpolate. 195 @param columnBorderMode Pixel extrapolation method in the horizontal direction. 196 197 @sa Sobel 198 */ 199 CV_EXPORTS Ptr<Filter> createSobelFilter(int srcType, int dstType, int dx, int dy, int ksize = 3, 200 double scale = 1, int rowBorderMode = BORDER_DEFAULT, int columnBorderMode = -1); 201 202 /** @brief Creates a vertical or horizontal Scharr operator. 203 204 @param srcType Source image type. 205 @param dstType Destination array type. 206 @param dx Order of the derivative x. 207 @param dy Order of the derivative y. 208 @param scale Optional scale factor for the computed derivative values. By default, no scaling is 209 applied. See getDerivKernels for details. 210 @param rowBorderMode Pixel extrapolation method in the vertical direction. For details, see 211 borderInterpolate. 212 @param columnBorderMode Pixel extrapolation method in the horizontal direction. 213 214 @sa Scharr 215 */ 216 CV_EXPORTS Ptr<Filter> createScharrFilter(int srcType, int dstType, int dx, int dy, 217 double scale = 1, int rowBorderMode = BORDER_DEFAULT, int columnBorderMode = -1); 218 219 //////////////////////////////////////////////////////////////////////////////////////////////////// 220 // Gaussian Filter 221 222 /** @brief Creates a Gaussian filter. 223 224 @param srcType Source image type. 225 @param dstType Destination array type. 226 @param ksize Aperture size. See getGaussianKernel for details. 227 @param sigma1 Gaussian sigma in the horizontal direction. See getGaussianKernel for details. 228 @param sigma2 Gaussian sigma in the vertical direction. If 0, then 229 \f$\texttt{sigma2}\leftarrow\texttt{sigma1}\f$ . 230 @param rowBorderMode Pixel extrapolation method in the vertical direction. For details, see 231 borderInterpolate. 232 @param columnBorderMode Pixel extrapolation method in the horizontal direction. 233 234 @sa GaussianBlur 235 */ 236 CV_EXPORTS Ptr<Filter> createGaussianFilter(int srcType, int dstType, Size ksize, 237 double sigma1, double sigma2 = 0, 238 int rowBorderMode = BORDER_DEFAULT, int columnBorderMode = -1); 239 240 //////////////////////////////////////////////////////////////////////////////////////////////////// 241 // Morphology Filter 242 243 /** @brief Creates a 2D morphological filter. 244 245 @param op Type of morphological operation. The following types are possible: 246 - **MORPH_ERODE** erode 247 - **MORPH_DILATE** dilate 248 - **MORPH_OPEN** opening 249 - **MORPH_CLOSE** closing 250 - **MORPH_GRADIENT** morphological gradient 251 - **MORPH_TOPHAT** "top hat" 252 - **MORPH_BLACKHAT** "black hat" 253 @param srcType Input/output image type. Only CV_8UC1 and CV_8UC4 are supported. 254 @param kernel 2D 8-bit structuring element for the morphological operation. 255 @param anchor Anchor position within the structuring element. Negative values mean that the anchor 256 is at the center. 257 @param iterations Number of times erosion and dilation to be applied. 258 259 @sa morphologyEx 260 */ 261 CV_EXPORTS Ptr<Filter> createMorphologyFilter(int op, int srcType, InputArray kernel, Point anchor = Point(-1, -1), int iterations = 1); 262 263 //////////////////////////////////////////////////////////////////////////////////////////////////// 264 // Image Rank Filter 265 266 /** @brief Creates the maximum filter. 267 268 @param srcType Input/output image type. Only CV_8UC1 and CV_8UC4 are supported. 269 @param ksize Kernel size. 270 @param anchor Anchor point. The default value (-1) means that the anchor is at the kernel center. 271 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 272 @param borderVal Default border value. 273 */ 274 CV_EXPORTS Ptr<Filter> createBoxMaxFilter(int srcType, Size ksize, 275 Point anchor = Point(-1, -1), 276 int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 277 278 /** @brief Creates the minimum filter. 279 280 @param srcType Input/output image type. Only CV_8UC1 and CV_8UC4 are supported. 281 @param ksize Kernel size. 282 @param anchor Anchor point. The default value (-1) means that the anchor is at the kernel center. 283 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 284 @param borderVal Default border value. 285 */ 286 CV_EXPORTS Ptr<Filter> createBoxMinFilter(int srcType, Size ksize, 287 Point anchor = Point(-1, -1), 288 int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 289 290 //////////////////////////////////////////////////////////////////////////////////////////////////// 291 // 1D Sum Filter 292 293 /** @brief Creates a horizontal 1D box filter. 294 295 @param srcType Input image type. Only CV_8UC1 type is supported for now. 296 @param dstType Output image type. Only CV_32FC1 type is supported for now. 297 @param ksize Kernel size. 298 @param anchor Anchor point. The default value (-1) means that the anchor is at the kernel center. 299 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 300 @param borderVal Default border value. 301 */ 302 CV_EXPORTS Ptr<Filter> createRowSumFilter(int srcType, int dstType, int ksize, int anchor = -1, int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 303 304 /** @brief Creates a vertical 1D box filter. 305 306 @param srcType Input image type. Only CV_8UC1 type is supported for now. 307 @param dstType Output image type. Only CV_32FC1 type is supported for now. 308 @param ksize Kernel size. 309 @param anchor Anchor point. The default value (-1) means that the anchor is at the kernel center. 310 @param borderMode Pixel extrapolation method. For details, see borderInterpolate . 311 @param borderVal Default border value. 312 */ 313 CV_EXPORTS Ptr<Filter> createColumnSumFilter(int srcType, int dstType, int ksize, int anchor = -1, int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0)); 314 315 //! @} 316 317 }} // namespace cv { namespace cuda { 318 319 #endif /* __OPENCV_CUDAFILTERS_HPP__ */ 320