当前位置:网站首页>DCT变换与反变换
DCT变换与反变换
2022-08-09 13:05:00 【zhouyongku】
输出
[email protected]:~/work/test$ g++ -o dct dct.cpp;./dct
-----------------------------Raw------------------------------------------------
11.000 85.000 136.000 212.000 211.000 233.000 137.000 135.000 155.000 107.000
167.000 74.000 44.000 129.000 53.000 211.000 179.000 178.000 205.000 212.000
6.000 56.000 60.000 224.000 193.000 61.000 3.000 237.000 59.000 106.000
142.000 70.000 192.000 22.000 27.000 147.000 255.000 164.000 26.000 154.000
16.000 193.000 228.000 60.000 66.000 25.000 15.000 246.000 203.000 221.000
-----------------------------DCT------------------------------------------------
898.167 -161.900 -29.099 -44.434 -86.667 -8.061 10.931 -25.984 88.233 -76.743
58.083 -18.356 -174.996 2.133 130.274 75.038 10.661 66.818 -103.008 -48.442
71.219 -10.792 37.247 -58.338 -52.775 -70.851 -106.499 38.895 -13.257 38.711
-30.607 72.646 -138.892 40.621 3.253 -71.651 61.859 1.966 30.639 59.597
-61.381 29.005 -84.221 -198.475 -66.858 151.349 -97.927 -119.957 18.692 -52.671
----------------------------IDCT-------------------------------------------------
11.000 85.000 136.000 212.000 211.000 233.000 137.000 135.000 155.000 107.000
167.000 74.000 44.000 129.000 53.000 211.000 179.000 178.000 205.000 212.000
6.000 56.000 60.000 224.000 193.000 61.000 3.000 237.000 59.000 106.000
142.000 70.000 192.000 22.000 27.000 147.000 255.000 164.000 26.000 154.000
16.000 193.000 228.000 60.000 66.000 25.000 15.000 246.000 203.000 221.000
[email protected]:~/work/test$
代码dct.cpp
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#define PI 3.1415926
void IDCT( double ** input, double ** output, int row, int col )
{
double ALPHA, BETA;
int u = 0;
int v = 0;
int i = 0;
int j = 0;
for(i = 0; i < row; i++)
{
for( j = 0; j < col; j++)
{
double tmp = 0.0;
for(u = 0; u < row; u++)
{
for(v = 0; v < col; v++)
{
if(u == 0)
{
ALPHA = sqrt(1.0 / row);
}
else
{
ALPHA = sqrt(2.0 / row);
}
if(v == 0)
{
BETA = sqrt(1.0 / col);
}
else
{
BETA = sqrt(2.0 / col);
}
tmp += ALPHA * BETA * *((double*) input + col*u + v )* cos((2*i+1)*u*PI/(2.0 * row)) * cos((2*j+1)*v*PI/(2.0 * col));
}
}
*((double*) output + col*i + j) = tmp;
}
}
}
void DCT( double ** input, double ** output, int row, int col )
{
// cout<<"Test in DCT"<<endl;
double ALPHA, BETA;
int u = 0;
int v = 0;
int i = 0;
int j = 0;
for(u = 0; u < row; u++)
{
for(v = 0; v < col; v++)
{
if(u == 0)
{
ALPHA = sqrt(1.0 / row);
}
else
{
ALPHA = sqrt(2.0 / row);
}
if(v == 0)
{
BETA = sqrt(1.0 / col);
}
else
{
BETA = sqrt(2.0 / col);
}
double tmp = 0.0;
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
tmp += *((double*) input + col*i + j ) * cos((2*i+1)*u*PI/(2.0 * row)) * cos((2*j+1)*v*PI/(2.0 * col));
}
}
*((double*) output + col*u + v) = ALPHA * BETA * tmp;
}
}
// cout << "The result of DCT:" << endl;
// for(int m = 0; m < row; m++)
// {
// for(int n= 0; n < col; n++)
// {
// cout <<setw(8)<< *((double*) output + col*m + n)<<" \t";
// }
// cout << endl;
// }
}
void InitArray( double **pArray,int row,int col )
{
srand(time(0));
for( int i=0;i<row;i++ )
{
for( int j=0;j<col;j++ )
{
double f= (rand()%256)*1.0;
double *p = (double*)pArray+i*col+j;
*p=f;
// printf("pointer=0x%x,data=%f\n",p,f);
}
}
}
void PrintArray( double ** pArray,int row,int col )
{
for( int i=0;i<row;i++ )
{
for( int j=0;j<col;j++ )
{
printf("%3.03f ",*((double*)pArray+i*col+j));
}
printf("\n");
}
}
int main( int argc,char ** argv )
{
double arr[5][10];
double arrnew[5][10];
double arri[5][10];
InitArray((double**)arr,5,10);
printf("-----------------------------Raw------------------------------------------------\n");
PrintArray((double**)arr,5,10);
DCT((double**)arr,(double**)arrnew,5,10);
printf("-----------------------------DCT------------------------------------------------\n");
PrintArray((double**)arr,5,10);
IDCT((double**)arrnew,(double**)arri,5,10);
printf("----------------------------IDCT-------------------------------------------------\n");
PrintArray((double**)arri,5,10);
return 0;
}
边栏推荐
猜你喜欢

5G Unicom Network Management Design Ideas

技嘉显卡 RGBFusion 不能调光解决方法

npm install失败

5G China unicom AP:B SMS ASCII Transcoding Requirements

关于做2D游戏时,Canvas边界显示在Game窗口的问题

Come and throw eggs.

七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)

5G China unicom AP:B SMS ASCII 转码要求

GIN Bind mode to get parameters and form validation
![行程和用户[阅读理解法]](/img/4b/77bba3c488b5410fdec5c3894c7421.png)
行程和用户[阅读理解法]
随机推荐
NFS pays special attention to the problem of permissions
jenkins api create custom pipeline
ftplib+ tqdm 上传下载进度条
Final assignment of R language data analysis in a university
力扣解法汇总1413-逐步求和得到正数的最小值
R language kaggle game data exploration and visualization
FFmpeg多媒体文件处理(FFMPEG日志系统)
基于 R 语言的判别分析介绍与实践 LDA和QDA
Q_08 更多信息
5G China unicom 一般性异常处理
GIN文件上传与返回
搭建大型分布式服务(二)搭建会员服务
How to reduce the size of desktop icons after the computer is reinstalled
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 16 Assignment
面试攻略系列(四)-- 你不知道的大厂面试
JS动画函数封装
GIN中GET POST PUT DELETE请求
ArcEngine(九)图形绘制
WPF 系统托盘 图标闪烁
uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)