模糊 Smoothing
GaussianBlur( src, dst, Size( 9, 9 ), 0, 0);
medianBlur( src, dst2, 9);
锐化边缘 Sharpening
Sobel(src, dst, -1, 1, 1 );
Laplacian(src, dst2, -1 );
滤波 Pyramids
pyrDown(src, dst);
pyrDown(dst, dst2);
pyrUp(dst2, dst);
pyrUp(dst, src);
形态运算 Morphological operations
inRange(src, Scalar(0, 0, 100), Scalar(40, 30, 255), dst);
Mat element = getStructuringElement(MORPH_ELLIPSE,Size(15,15));
dilate(dst, dst2, element);
erode(dst2, dst3, element);
查找表 Look-up tables (LUTs)
uchar * M = (uchar*)malloc(256*sizeof(uchar));
for(int i=0; i<256; i++){
M[i] = i*0.5;
}
Mat lut(1, 256, CV_8UC1, M);
// Apply the LUT
Mat dst;
LUT(src,lut,dst);
几何变换 Geometrical transformations
仿射变换 Affine
缩放 scale
resize(src, dst, Size(0,0), 0.5, 0.5);
位移 Translation
Mat M = (Mat_(2,3) << 1, 0, 200, 0, 1, 150); warpAffine(src,dst,M,src.size());
旋转 rotation
Mat M = getRotationMatrix2D(Point2f(src.cols/2,src.rows/2),45,1); warpAffine(src,dst,M,src.size());
斜切 Skewing
double m = 1/tan(M_PI/3);
Mat M = (Mat_(2,3) << 1, m, 0, 0, 1, 0); warpAffine(src,dst,M,Size(src.cols+0.5*src.cols,src.rows));
翻转 reflextion
Mat Mh = (Mat_(2,3) << -1, 0, src.cols, 0, 1, 0
Mat Mv = (Mat_(2,3) << 1, 0, 0, 0, -1, src.rows);
Mat M = (Mat_(2,3) << -1, 0, src.cols, 0, -1, src.rows); warpAffine(src,dsth,Mh,src.size()); warpAffine(src,dstv,Mv,src.size()); warpAffine(src,dst,M,src.size());