Smooth

Smooth

Smooths the image in one of several ways.

C:  void  cvSmooth (const CvArr*  src, CvArr*  dst, int  smoothtype=CV_GAUSSIAN, int  param1=3, int  param2=0, double  param3=0, double  param4=0 )
Python:   cv. Smooth (src, dst, smoothtype=CV_GAUSSIAN, param1=3, param2=0, param3=0, param4=0 ) → None
Parameters:
  • src – The source image
  • dst – The destination image
  • smoothtype –

    Type of the smoothing:

    • CV_BLUR_NO_SCALE linear convolution with \texttt{param1}\times\texttt{param2} box kernel (all 1’s). If you want to smooth different pixels with different-size box kernels, you can use the integral image that is computed using integral()
    • CV_BLUR linear convolution with \texttt{param1}\times\texttt{param2} box kernel (all 1’s) with subsequent scaling by 1/(\texttt{param1}\cdot\texttt{param2})
    • CV_GAUSSIAN linear convolution with a \texttt{param1}\times\texttt{param2} Gaussian kernel
    • CV_MEDIAN median filter with a \texttt{param1}\times\texttt{param1} square aperture
    • CV_BILATERAL bilateral filter with a \texttt{param1}\times\texttt{param1} square aperture, color sigma= param3 and spatial sigma= param4 . If param1=0 , the aperture square side is set tocvRound(param4*1.5)*2+1 . Information about bilateral filtering can be found at http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
  • param1 – The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
  • param2 – The second parameter of the smoothing operation, the aperture height. Ignored by CV_MEDIAN and CV_BILATERAL methods. In the case of simple scaled/non-scaled and Gaussian blur if param2 is zero, it is set to param1 . Otherwise it must be a positive odd number.
  • param3 –

    In the case of a Gaussian parameter this parameter may specify Gaussian \sigma (standard deviation). If it is zero, it is calculated from the kernel size:

    \sigma  = 0.3 (n/2 - 1) + 0.8  \quad   \text{where}   \quad  n= \begin{array}{l l} \mbox{\texttt{param1} for horizontal kernel} \\ \mbox{\texttt{param2} for vertical kernel} \end{array}

    Using standard sigma for small kernels ( 3\times 3 to 7\times 7 ) gives better speed. If param3 is not zero, while param1 and param2 are zeros, the kernel size is calculated from the sigma (to provide accurate enough operation).

The function smooths an image using one of several methods. Every of the methods has some features and restrictions listed below:

  • Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format (similar to Sobel() and Laplacian()) and 32-bit floating point to 32-bit floating-point format.
  • Simple blur and Gaussian blur support 1- or 3-channel, 8-bit and 32-bit floating point images. These two methods can process images in-place.
  • Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.

in-place操作,源图像和目标图像是同一个图像


dilate

Dilates an image by using a specific structuring element.

C++:  void  dilate (InputArray  src, OutputArray  dst, InputArray  element, Point  anchor=Point(-1,-1), int  iterations=1, int  borderType=BORDER_CONSTANT, const Scalar&  borderValue=morphologyDefaultBorderValue()  )
Python:   cv2. dilate (src, kernel [, dst [, anchor [, iterations [, borderType [, borderValue ] ] ] ] ] ) → dst
C:  void  cvDilate (const CvArr*  src, CvArr*  dst, IplConvKernel*  element=NULL, int  iterations=1  )
Python:   cv. Dilate (src, dst, element=None, iterations=1 ) → None
Parameters:
  • src – Source image.
  • dst – Destination image of the same size and type as src .
  • element – Structuring element used for dilation. If element=Mat() , a 3 x 3 rectangular structuring element is used.
  • anchor – Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center.
  • iterations – Number of times dilation is applied.
  • borderType – Pixel extrapolation method. See borderInterpolate() for details.
  • borderValue – Border value in case of a constant border. The default value has a special meaning. See createMorphologyFilter() for details.

The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:

\texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')

The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In case of multi-channel images, each channel is processed independently.

See also

 

erode()morphologyEx()createMorphologyFilter()

erode

Erodes an image by using a specific structuring element.

C++:  void  erode (InputArray  src, OutputArray  dst, InputArray  element, Point  anchor=Point(-1,-1), int  iterations=1, int  borderType=BORDER_CONSTANT, const Scalar&  borderValue=morphologyDefaultBorderValue()  )
Python:   cv2. erode (src, kernel [, dst [, anchor [, iterations [, borderType [, borderValue ] ] ] ] ] ) → dst
C:  void  cvErode (const CvArr*  src, CvArr*  dst, IplConvKernel*  element=NULL, int  iterations=1 )
Python:   cv. Erode (src, dst, element=None, iterations=1 ) → None
Parameters:
  • src – Source image.
  • dst – Destination image of the same size and type as src .
  • element – Structuring element used for erosion. If element=Mat() , a 3 x 3 rectangular structuring element is used.
  • anchor – Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center.
  • iterations – Number of times erosion is applied.
  • borderType – Pixel extrapolation method. See borderInterpolate() for details.
  • borderValue – Border value in case of a constant border. The default value has a special meaning. See createMorphologyFilter() for details.

The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:

\texttt{dst} (x,y) =  \min _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')

The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In case of multi-channel images, each channel is processed independently.

See also

 

dilate()morphologyEx()createMorphologyFilter()

腐蚀操作通常是用来消除图像中的“斑点”噪声,在试图找到连同分支(即具有相似颜色或强度的像素点的大块的互相分离的区域)时通常使用膨胀操作。

为矩阵定义了一系列方便的操作符。我们可以将一个已经存在的灰度图像 img 变成全黑色:

img = Scalar(0);

选择感兴趣区域:

Rect r(10, 10, 100, 100);//第一个是cols第二个是rows第三个是width第四个是height
Mat smallImg = img(r);

将图像的类型从8UC1转为32FC1:

src.convertTo(dst, CV_32F);

在算法开发过程中,查看算法的中间结果是非常有用的。OpenCV提供了方便查看图像的方法。类型为 8U 的图像可以使用如下方法显示:

Mat img = imread("image.jpg");

namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", img);
waitKey();

调用 waitKey() 会进入一个消息循环,来等待 image 窗口上的按键动作。 类型为 32F 的图像需要转为 8U 类型。如下:

Mat img = imread("image.jpg");
Mat grey;
cvtColor(img, grey, CV_BGR2GREY);

Mat sobelx;
Sobel(grey, sobelx, CV_32F, 1, 0);

double minVal, maxVal;
minMaxLoc(sobelx, &minVal, &maxVal); //find minimum and maximum intensities
Mat draw;
sobelx.convertTo(draw, CV_8U, 255.0/(maxVal - minVal), -minVal);

namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", draw);
waitKey();

cvFindContours()

cvInitLineIterator函数来获取每一横线上的像素值,如果为空,说明是空白行


猜你喜欢

转载自blog.csdn.net/weixin_41484240/article/details/81001207