基于OpenCV的离散正弦变换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35759050/article/details/72331303

离散正弦变换(Discrete SineTransform, DST):

类似于DCT,离散正弦变换也有八种形式,常用的是DST-Ⅰ,一般我们提到DST而不特殊说明即指DST-Ⅰ。

这里直接给出DST-Ⅰ的定义:

正变换:


逆变换:


因此可得到变换矩阵SN

变换矩阵SN是一个正交矩阵,而且它还是一个对称矩阵(转置与本身相等),所以正变换与反变换是相同的。

基于OpenCV离散正弦变换:


void MainWindow::on_pushButton_10_clicked()
{
    Mat img = imread("D:/Pic/2.jpg",0);

    Mat src(img.rows,img.cols,CV_64FC1);
    img.convertTo(src,CV_64FC1);

    Mat dst(src.rows,src.cols,CV_64FC1);

    double pi = 3.141592657;
    Mat tmp(200,200,CV_64FC1);
    int N = 200;
    for(int i=0;i<200;i++)
        for(int j=0;j<200;j++)
        {
            tmp.at<double>(j,i) = (double)(sin(pi*i*j/(N+1))*pow(2/(N+1),1/2));
        }

    dst = tmp*src*tmp/45000;
    imshow("dst",dst);
    Plot* plot = new Plot(dst);
    //QGridLayout *grid = new QGridLayout(ui->frame);
    //grid->addWidget(plot,0,0);

    //plot->setTitle("3D");
    plot->coordinates()->axes[X1].setLabelString("X(um)");  //只能写在这
    plot->coordinates()->axes[Y1].setLabelString("Y(um)");  //设置坐标轴标签
    plot->coordinates()->axes[Z1].setLabelString("Z(nm)");
    plot->coordinates()->axes[Z2].setLabelString("Z(nm)");
    plot->coordinates()->axes[Z3].setLabelString("Z(nm)");
    plot->coordinates()->axes[Z4].setLabelString("Z(nm)");

    double start,stop;  //设置颜色条
    plot->coordinates()->axes[Z1].limits(start,stop);
    plot->legend()->setLimits(start,stop);
//    plot->legend()->setAutoScale(true);
    plot->resize(700,600);
    plot->show();
    //grid->~QGridLayout();
}

效果图:




猜你喜欢

转载自blog.csdn.net/qq_35759050/article/details/72331303
今日推荐