OpenCV离散余弦变换原理与源码

环境配置:VS2012  OpenCV2.4.9

OpenCV离散余弦变换原理与源码_第1张图片

代码:

#include "highgui.h"
#include "math.h"
#include "cv.h"
#include "stdlib.h"

using namespace cv;

void DCT(Mat &src, Mat &dst)
{
	double pi = 3.141592657;
	Mat C_Mat(src.rows,src.cols, CV_64FC1);
	Mat CT_Mat(src.rows,src.cols, CV_64FC1);

	for(int j=0;j(0,j) = sqrt(2.0/(C_Mat.rows))*sqrt(1.0/2);

	for(int i=1;i(i,j) = sqrt(2.0/(C_Mat.rows))*cos(pi*(i-1)*(2*j-1)/2/(C_Mat.rows));

	CT_Mat = C_Mat.t();

	dst = C_Mat*src*CT_Mat;
}

void main()
{
	Mat img = imread("D:/Pic/4.jpg",0);
	//imshow("img",img);
	Mat src(img.rows,img.cols,CV_64FC1);
	img.convertTo(src,CV_64FC1);
	//imshow("src",src);
	Mat dst(src.rows,src.cols,CV_64FC1);
	DCT(src,dst);
	imshow("dst",dst);
	cvWaitKey(0);
}



你可能感兴趣的:(OpenCV图像处理)