steerable filter

#include"stdafx.h"
#include"stdlib.h"
#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\core\core.hpp>
#include<opencv2\ml\ml.hpp>
#include<opencv2\imgproc\imgproc.hpp>

using namespace std;
using namespace cv;

#define Pai 3.1415926535897932384626


函数声明
Mat steerable_filter(Mat src, int angle);
Mat threshold(Mat srcimage);
Mat x2_Filter(Mat src);

 

int main()
{

    Mat src = imread("101.bmp");
    Mat gray;
    cvtColor(src, gray, COLOR_BGR2GRAY);
    Mat dst= steerable_filter(gray,45);

    Mat augimg,cannyimg;
    addWeighted(gray, 0.3, dst, 0.7, 0, augimg);

    GaussianBlur(augimg, augimg, Size(3, 3), 0, 0);
    Canny(augimg, cannyimg, 30, 100);
    namedWindow("cannyimg", 0);
    imshow("cannyimg", cannyimg);
    namedWindow("augimg", 0);
    imshow("augimg", augimg);
    namedWindow("steerableFilter", 0);
    imshow("steerableFilter", dst);
    waitKey(0);

}

 

 

 

Mat steerable_filter(Mat src,int angle)src为灰度图像,angle为方向角度
{
    double  theta;
    theta = (angle*(Pai / 180));
    Mat Gxx, abs_Gxx, Gxy, Gyy,abs_Gyy, abs_Gxy;

    ///****************2阶Sobel,Gxx,Gyy,Gxy**********************/
    Sobel(src,Gxx, CV_16S, 2, 0, 3);
    Gxx.convertTo(abs_Gxx,CV_8U);
    Sobel(src,Gyy, CV_16S, 0, 2, 3);
    Gyy.convertTo(abs_Gyy, CV_8U);
    Sobel(src,Gxy, CV_16S, 2, 2, 3);
    Gxy.convertTo(abs_Gxy, CV_8U);

    
    Mat output_16S(Gxx.size(), CV_16S, Scalar::all(0));
    Mat output_8U;
    for (int i = 0; i < Gxx.rows; i++)
    {
        uchar* value_Gxx = abs_Gxx.ptr<uchar>(i);
        uchar* value_Gyy = abs_Gyy.ptr<uchar>(i);
        uchar* value_Gxy = abs_Gxy.ptr<uchar>(i);
        short* out_16 = output_16S.ptr<short>(i);
        for (int j = 0; j < Gxx.cols; j++)
        {
            double t_Gxx, t_Gyy, t_Gxy;
            t_Gxx = value_Gxx[j] * cos(theta) * cos(theta);
            t_Gyy = value_Gyy[j] * sin(theta) * sin(theta);
            t_Gxy = 2 * value_Gxy[j] * cos(theta) * sin(theta);
            out_16[j] = abs(t_Gxx)+ abs(t_Gyy) +abs(t_Gxy);
            
        }
    }

    //cout << output_16S << endl;
    output_16S.convertTo(output_8U, CV_8U);
    
    namedWindow("abs_Gxx", 0);
    imshow("abs_Gxx", abs_Gxx);
    namedWindow("abs_Gyy", 0);
    imshow("abs_Gyy", abs_Gyy);
    namedWindow("abs_Gxy", 0);
    imshow("abs_Gxy", abs_Gxy);
    namedWindow("output_8", 0);
    imshow("output_8", output_8U);
    return output_8U;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值