当前位置:网站首页>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;
}
边栏推荐
- uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)
- Periodic sharing of Alibaba Da Tao system model governance
- NC161 二叉树的中序遍历
- GIN中GET POST PUT DELETE请求
- 【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
- 行程和用户[阅读理解法]
- Q_04_05 使用Qubits
- jenkins api create custom pipeline
- 力扣解法汇总1413-逐步求和得到正数的最小值
- handwritten big pile
猜你喜欢

5G Unicom Network Management Design Ideas

乐东消防救援大队应邀为干部开展消防安全培训

01_iTween_第一天--小球抛物线

Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation

The sword refers to the offer, cuts the rope 2

IDEA Gradle 常遇问题(一)

How to reduce the size of desktop icons after the computer is reinstalled

gin的中间件和路由分组

FFmpeg多媒体文件处理(ffmpeg处理流数据的基本概念)

GIN Bind mode to get parameters and form validation
随机推荐
Draw a histogram with plot_hist_numeric()
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
Q_08 更多信息
【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
NFS pays special attention to the problem of permissions
npm install失败
gin的中间件和路由分组
CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
javscript基础易错点集合
NC84 完全二叉树结点数
Yocto 可以下载的第三方库
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
NC96 判断一个链表是否为回文结构
NC193 二叉树的前序遍历
NC7 买卖股票的最好时机(一)
Unicom network management protocol block diagram
glibc 内存管理模型 释放 C库内存缓存
NC15 求二叉树的层序遍历
5G Unicom Network Management Design Ideas
陈强教授《机器学习及R应用》课程 第十六章作业