OpenCV-imgproc模块-学习记录

图像平滑处理:      

归一化块(均值)滤波器:

blur(src, dst_blur, Size(i, i));

高斯滤波器:

GaussianBlur(src, dst_GaussianBlur, Size(i, i), 0, 0);

中值滤波:

medianBlur(src, dst_medianBlur, i);

双边滤波:

bilateralFilter(src, dst_bilateralFilter, i, i * 2, i / 2);

      

腐蚀和膨胀:

src:原始图dst:输出图kernel内核:矩形 交叉形 椭圆形
kernel = getStructuringElement(k, Size(1,1));
k = 0 , 内核形状矩形  k=1,内核形状交叉性 k=2,内核形状椭圆形
size 改变内核的大小
腐蚀操作: erode(src,dst,kernel)
膨胀操作:dilate(src,dst,kernel)
第一个拖条控制内核的大小,第二个拖条控制内核的形状

        


更多形态变化:

        kernel是内核形状,和上面相同

operation为运算方式:
operation=2:开运算 
operation=3:闭运算
operation=4:形态梯度 
operation=5:顶帽 
operation=6:黑帽

morphologyEx(src2, dst, operation, kernel);

             
        (原图,开运算,闭运算)

            
        (形态梯度,顶帽,黑帽)


放大和缩小:

放大:pyrUp(temp, dst_Up, Size(temp.cols * 2, temp.rows * 2));
缩小:pyrDown(temp, dst_Up, Size(temp.cols / 2, temp.rows / 2));
图片Size小了但还用原来的Size显示出来所以就模糊了

                

    

阈值操作:

        threshold_value阈值,threshold_type 0-4, 7,8,16使用了有错误

        threshold(src2, dst_Threshold,threshold_value,255,threshold_type);

        

        

        
(值越大图恢复过来了)

        

        

    

让边缘更加明显:

Sobel 导数:Sobel算子结合高斯平滑和微分,用于抗噪音。

CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
                         int dx, int dy, int ksize = 3,
                         double scale = 1, double delta = 0,
                         int borderType = BORDER_DEFAULT );

        

     
        /// 求 X方向梯度
	//Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
	Sobel(Arithmetic_Src, grad_x, ddepth, 1, 0, 3);
	convertScaleAbs(grad_x, abs_grad_x);
	/// 求Y方向梯度
	//Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
	Sobel(Arithmetic_Src, grad_y, ddepth, 0, 1, 3); 
	convertScaleAbs(grad_y, abs_grad_y);

	/// 合并梯度(近似)
	//addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
	double a = alpha / 100.0;
	double b = beta / 100.0;
	double c = gamma / 100.0;
	addWeighted(abs_grad_x, a, abs_grad_y,b, gamma, grad);

                计算X,Y方向梯度,再合并起来。下图可以看出,xy的鼻子上下和衣领 是不同的。


       
Laplacian算法size参数越大,图片轮廓越不清    晰,内核深度2为 CV_16U  ,3为CV_16S       

CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
                             int ksize = 1, double scale = 1, double delta = 0,
                             int borderType = BORDER_DEFAULT );
        可以看出内核深度高的,轮廓也会相对明显。


        

Canny算法:有2个构造函数,区别就是输入图像不同;

/**
@param image 8-bit input image.
@param edges output edge map; single channels 8-bit image, which has the same size as image .
@param threshold1 first threshold for the hysteresis procedure.
@param threshold2 second threshold for the hysteresis procedure.
@param apertureSize aperture size for the Sobel operator.
@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
L2gradient=false ).
 */
CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
                         double threshold1, double threshold2,
                         int apertureSize = 3, bool L2gradient = false );

/** \overload

Finds edges in an image using the Canny algorithm with custom image gradient.

@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3).
@param dy 16-bit y derivative of input image (same type as dx).
@param edges,threshold1,threshold2,L2gradient See cv::Canny
 */
CV_EXPORTS_W void Canny( InputArray dx, InputArray dy,
                         OutputArray edges,
                         double threshold1, double threshold2,
                         bool L2gradient = false );





霍夫线变换

统计概率霍夫线变换


直方图均匀化:

        左图为载入的灰度图像,右图为直方图均匀化后的图像。

    cvtColor(Histogram_Src, Histogram_Dst, CV_BGR2GRAY);
	equalizeHist(Histogram_Dst, dst);






        


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值