void GaussianBlur
@param src input image; the image can have any number of channels, which are processed
independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
@param dst output image of the same size and type as src.
@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
positive and odd. Or, they can be zero's and then they are computed from sigma.
@param sigmaX Gaussian kernel standard deviation in X direction.
@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
respectively (see cv::getGaussianKernel for details); to fully control the result regardless of
possible future modifications of all this semantics, it is recommended to specify all of ksize,
sigmaX, and sigmaY.
@param borderType pixel extrapolation method, see cv::BorderTypes
@sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur
*/
CV_EXPORTS_Wvoid GaussianBlur( InputArraysrc,OutputArray dst, Size ksize,
double sigmaX , double sigmaY= 0,
int borderType = BORDER_DEFAULT );
void medianBlur 顾名思义:输出图像的像素值是领域的中值
void bilateralBlur
This filter does not work inplace.
@param src Source 8-bit or floating-point, 1-channel or 3-channel image.
@param dst Destination image of the same size and type as src .
@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
it is computed from sigmaSpace.
@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
in larger areas of semi-equal color.
@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that
farther pixels will influence each other as long as their colors are close enough (see sigmaColor
). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
proportional to sigmaSpace.
@param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
*/
CV_EXPORTS_Wvoid bilateralFilter( InputArray src,OutputArray dst, int d,
double sigmaColor , double sigmaSpace,
int borderType = BORDER_DEFAULT );
void blur 使用归一化的盒式滤波来平滑图像
#include"opencv2/opencv.hpp"
#include"opencv.hpp"
#include
usingnamespacestd;
usingnamespacecv;
intmain(intargc,char**argv)
{
//read the src image
Matsrc;
src=imread("math.png");
//open the fliter
Matdst, dst2;
GaussianBlur(src, dst,Size(9, 9), 0, 0);
medianBlur(src, dst2, 9);
//show
namedWindow("Original image",WINDOW_AUTOSIZE);
imshow("Original image", src);
namedWindow("Gussian blur",WINDOW_AUTOSIZE);
imshow("Gussian blur", dst);
namedWindow("Median blur",WINDOW_AUTOSIZE);
imshow("Median blur", dst2);
//wait
waitKey();
return0;
}
@param src input image.
@param dst output image of the same size and the same number of channels as src .
@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
8-bit input images it will result in truncated derivatives.
当值为-1时,输出与输入图像的深度相同
@param dx order of the derivative x.
@param dy order of the derivative y. 表示希望求导的阶
@param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
@param scale optional scale factor for the computed derivative values; by default, no scaling is
applied (see cv::getDerivKernels for details). 建立计算导数值得尺度因子
@param delta optional delta value that is added to the results prior to storing them in dst.
@param borderType pixel extrapolation method, see cv::BorderTypes
@sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar
void Scharr 用于计算一个3*3大小的核更精确的导数
@param src input image.
@param dst output image of the same size and the same number of channels as src.
@param ddepth output image depth, see @ref filter_depths "combinations"
@param dx order of the derivative x.
@param dy order of the derivative y.
@param scale optional scale factor for the computed derivative values; by default, no scaling is
applied (see getDerivKernels for details).
@param delta optional delta value that is added to the results prior to storing them in dst.
@param borderType pixel extrapolation method, see cv::BorderTypes
@sa cartToPolar
*/
CV_EXPORTS_Wvoid Scharr( InputArraysrc,OutputArray dst, int ddepth,
int dx , int dy,double scale = 1, double delta= 0,
int borderType = BORDER_DEFAULT );
void Laplacian 用于计算一幅图像的Laplacian值
除了ksize之外所有的参数和sobel &scharr 中的相同
ksize==1 使用3*3的核(中心值为-4,四个角的值为0,其余值为1)对图像进行滤波
ksize>1 使用Sobel算子通过累加x的二阶导数和y的二阶导数来计算源图像的Laplacian
@param src Source image.
@param dst Destination image of the same size and the same number of channels as src .
@param ddepth Desired depth of the destination image.
@param ksize Aperture size used to compute the second-derivative filters. See getDerivKernels for
details. The size must be positive and odd.
@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
applied. See getDerivKernels for details.
@param delta Optional delta value that is added to the results prior to storing them in dst .
@param borderType Pixel extrapolation method, see cv::BorderTypes
@sa Sobel, Scharr
*/
CV_EXPORTS_Wvoid Laplacian( InputArraysrc,OutputArray dst, int ddepth,
int ksize = 1, double scale= 1, double delta= 0,
int borderType = BORDER_DEFAULT );
#include"opencv2/opencv.hpp"
#include"opencv.hpp"
#include
usingnamespacestd;
usingnamespacecv;
intmain(intargc,char**argv)
{
//read the src image
Matsrc;
src=imread("go.png");
//sharpen
Matdst, dst2;
Sobel(src, dst, -1, 0, 0);
Laplacian(src, dst2, -1);
//show
namedWindow("Original image",WINDOW_AUTOSIZE);
imshow("Original image", src);
namedWindow("Sobel",WINDOW_AUTOSIZE);
imshow("Soble", dst);
namedWindow("Laplacian",WINDOW_AUTOSIZE);
imshow("Laplacian", dst2);
//wait
waitKey();
return0;
}
#include"opencv2/opencv.hpp"
#include"opencv.hpp"
#include
usingnamespacestd;
usingnamespacecv;
intmain(intargc,char**argv)
{
//read the src image
Matsrc;
src=imread("cat2.png");
//pyrDown*2
Matdst, dst2;
pyrDown(src, dst);
pyrDown(dst, dst2);
//show
namedWindow("Original image",WINDOW_AUTOSIZE);
imshow("Original image", src);
namedWindow("1st pyrDown",WINDOW_AUTOSIZE);
imshow("1st pyrDown", dst);
namedWindow("2st pyrDown",WINDOW_AUTOSIZE);
imshow("2st pyrDown", dst2);
//pyrUp
pyrUp(dst2, dst);
pyrUp(dst, src);
//show
namedWindow("New",WINDOW_AUTOSIZE);
imshow("New", dst2);
namedWindow("1st pyrUp",WINDOW_AUTOSIZE);
imshow("1st pyrUp", dst);
namedWindow("2st pyrUp",WINDOW_AUTOSIZE);
imshow("2st pyrUp", src);
//wait
waitKey();
return0;
}
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.
@param src input image; the number of channels can be arbitrary, but the depth should be one of
CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
@param dst output image of the same size and type as src\`.
@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
structuring element is used. Kernel can be created using getStructuringElement
@param anchor position of the anchor within the element; default value (-1, -1) means that the
anchor is at the element center.
@param iterations number of times dilation is applied. 迭代的次数,可以多次执行该运算
@param borderType pixel extrapolation method, see cv::BorderTypes
@param borderValue border value in case of a constant border
@sa erode, morphologyEx, getStructuringElement
*/
CV_EXPORTS_Wvoid dilate( InputArraysrc,OutputArray dst, InputArray kernel,
Point anchor = Point(-1,-1), int iterations= 1,
int borderType = BORDER_CONSTANT,
const Scalar & borderValue = morphologyDefaultBorderValue() );
void erode 对源图像进行腐蚀运算,结果储存在目标图像中
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.
@param src input image; the number of channels can be arbitrary, but the depth should be one of
CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
@param dst output image of the same size and type as src.
@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
structuring element is used. Kernel can be created using getStructuringElement.
@param anchor position of the anchor within the element; default value (-1, -1) means that the
anchor is at the element center.
@param iterations number of times erosion is applied.
@param borderType pixel extrapolation method, see cv::BorderTypes
@param borderValue border value in case of a constant border
@sa dilate, morphologyEx, getStructuringElement
*/
CV_EXPORTS_Wvoid erode( InputArraysrc,OutputArray dst, InputArray kernel,
Point anchor = Point(-1,-1), int iterations= 1,
int borderType = BORDER_CONSTANT,
const Scalar & borderValue = morphologyDefaultBorderValue() );
void morphologyEx 执行使用参数op定义的形态学运算
The function can perform advanced morphological transformations using an erosion and dilation as
basic operations.
Any of the operations can be done in-place. In case of multi-channel images, each channel is
processed independently.
@param src Source image. The number of channels can be arbitrary. The depth should be one of
CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
@param dst Destination image of the same size and type as src\` .
@param kernel Structuring element. It can be created using getStructuringElement.
@param anchor Anchor position with the kernel. Negative values mean that the anchor is at the
kernel center.
@param op Type of a morphological operation, see cv::MorphTypes
@param iterations Number of times erosion and dilation are applied.
@param borderType Pixel extrapolation method, see cv::BorderTypes
@param borderValue Border value in case of a constant border. The default value has a special
meaning.
@sa dilate, erode, getStructuringElement
*/
CV_EXPORTS_Wvoid morphologyEx( InputArraysrc,OutputArray dst,
int op , InputArray kernel,
Point anchor = Point(-1,-1), int iterations= 1,
int borderType = BORDER_CONSTANT,
const Scalar & borderValue = morphologyDefaultBorderValue() );
Mat getStructuringElement 返回一个指定大小和形状的结构元素
The function constructs and returns the structuring element that can be further passed to cv::erode,
cv::dilate or cv::morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as
the structuring element.
@param shape Element shape that could be one of cv::MorphShapes
@param ksize Size of the structuring element.
@param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the
anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor
position. In other cases the anchor just regulates how much the result of the morphological
operation is shifted.
*/
CV_EXPORTS_WMat getStructuringElement(intshape,Size ksize , Point anchor= Point(-1,-1));
#include"opencv2/opencv.hpp"
#include"opencv.hpp"
#include
usingnamespacestd;
usingnamespacecv;
intmain(intargc,char**argv)
{
//read the src image
Matsrc;
src=imread("go.png");
//blur
Matdst, dst2,dst3,dst4,dst5;
inRange(src,Scalar(210, 210, 210),Scalar(255,255, 255), dst);//二值化阀值
Matelement = getStructuringElement(MORPH_ELLIPSE,Size(15, 15));
//closed operation
dilate(dst, dst2, element);
erode(dst2, dst3, element);
//open operation
erode(dst, dst4, element);
dilate(dst4, dst5, element);
//show
namedWindow("Original image",WINDOW_AUTOSIZE);
imshow("Original image", src);
namedWindow("Segmented",WINDOW_AUTOSIZE);
imshow("Segmented", dst);
/* namedWindow("Dilation", WINDOW_AUTOSIZE);
imshow("Dilation", dst2);
namedWindow("Dilation->Erision", WINDOW_AUTOSIZE);
imshow("Dilation->Erision", dst3);*/
//open operation
namedWindow("Dilation",WINDOW_AUTOSIZE);
imshow("Dilation", dst4);
namedWindow("Erision->Dilation",WINDOW_AUTOSIZE);
imshow("Erision->Dilation", dst5);
//wait
waitKey();
return0;
}