好文档 - 专业文书写作范文服务资料分享网站

小波变换C语言学习知识实现代码

天下 分享 时间: 加入收藏 我要投稿 点赞

-`

#include

#include

#define height 256

#define width 256

void twoDDWT(double org[][width], double dwt[][width],int NumofBand);

void oneDDWT(int flag, double org[][width], double dwt[][width]);

void twoDIDWT(double dwt[][width], double rec[][width],int NumofBand);

void oneDIDWT(int flag, double dwt[][width], double rec[][width]);

int main() { int i, j; double org[height][width], dwt[height][width],rec[height][width]; FILE *lena; FILE *lena3; FILE *lena4; lena = fopen(\, \); lena3 = fopen(\, \); lena4 = fopen(\, \); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { org[i][j] = fgetc(lena); } } twoDDWT(org, dwt,4); for (i = 0; i < height/2; i++) { for (j = 0; j < width/2; j++) { org[i][j]=dwt[i][j]; } } twoDDWT(org, dwt,7); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { fputc(dwt[i][j], lena3); } } twoDIDWT(dwt, rec,7);

-`

for (i = 0; i < height/2; i++) { for (j = 0; j < width/2; j++) { dwt[i][j]=rec[i][j]; } } twoDIDWT(dwt, rec,4); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { fputc(rec[i][j], lena4); } } return 0; }

void twoDDWT(double org[][width], double dwt[][width],int NumofBand) { if (NumofBand==4) { oneDDWT(0, org, dwt); oneDDWT(1, org, dwt); } if (NumofBand==7) { oneDDWT(2, org, dwt); oneDDWT(3, org, dwt); } }

void oneDDWT(int flag, double org[][width], double dwt[][width]) { int i, j; double temp[height][width], temp1[height][width]; double f_LPF[] = { -0.125, 0.25, 0.75, 0.25, -0.125 }; double f_HPF[] = { -0.5, 1, -0.5 }; if (flag == 0)//vertical direction { for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (j == 0) temp[i][j] = f_LPF[0] * org[i][j + 2] + f_LPF[1] * org[i][j + 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2]; else if (j == 1) temp[i][j] = f_LPF[0] * org[i][j] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2]; else if (j > 1 && j < height-2) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2];

-`

else if (j == height-2) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j]; else if (j == height-1) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j - 1] + f_LPF[4] * org[i][j - 2]; } } for (i = 0; i < height; i++) { for (j = 0; j < width/2; j++) { dwt[i][j] = temp[i][j * 2 + 1]; } } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (j == 0) temp[i][j] = f_HPF[0] * org[i][j + 1] + f_HPF[1] * org[i][j] + f_HPF[2] * org[i][j + 1]; else if (j > 0 && j < height-1) temp[i][j] = f_HPF[0] * org[i][j - 1] + f_HPF[1] * org[i][j] + f_HPF[2] * org[i][j + 1]; else if (j == height-1) temp[i][j] = f_HPF[0] * org[i][j - 1] + f_HPF[1] * org[i][j] + f_HPF[2] * org[i][j - 1]; } } for (i = 0; i < height; i++) { for (j = 0; j < width/2; j++) { dwt[i][j + width/2] = temp[i][j * 2]; } } } if (flag == 1)//horizontal direction { for (i = 0; i < height; i++) { for (j = 0; j < width/2; j++) { if (i == 0) temp[i][j] = f_LPF[0] * dwt[i + 2][j] + f_LPF[1] * dwt[i + 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i == 1) temp[i][j] = f_LPF[0] * dwt[i][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i > 1 && i < width-2) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i == width-2) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i][j]; else if (i == width-1) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i - 1][j] + f_LPF[4] * dwt[i - 2][j];

-`

} } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { temp1[i][j] = temp[i * 2 + 1][j]; } } for (i = 0; i < height; i++) { for (j = 0; j < width/2; j++) { if (i == 0) temp[i][j] = f_HPF[0] * dwt[i + 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i + 1][j]; else if (i > 0 && i < width-1) temp[i][j] = f_HPF[0] * dwt[i - 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i + 1][j]; else if (i == width-1) temp[i][j] = f_HPF[0] *dwt[i - 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i - 1][j]; } } for (i = 0; i < height; i++) { for (j = 0; j < width/2; j++) { temp1[i][j+width/2] = temp[i * 2][j]; } } for (i = 0; i < height; i++) { for (j = width/2; j < width; j++) { if (i == 0) temp[i][j] = f_LPF[0] * dwt[i + 2][j] + f_LPF[1] * dwt[i + 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i == 1) temp[i][j] = f_LPF[0] * dwt[i][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i > 1 && i < height-2) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i + 2][j]; else if (i == height-2) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i + 1][j] + f_LPF[4] * dwt[i][j]; else if (i == height-1) temp[i][j] = f_LPF[0] * dwt[i - 2][j] + f_LPF[1] * dwt[i - 1][j] + f_LPF[2] * dwt[i][j] + f_LPF[3] * dwt[i - 1][j] + f_LPF[4] * dwt[i - 2][j]; } } for (i = 0; i < height; i++) { for (j = width/2; j < width; j++) { temp1[i+height/2][j-width/2] = temp[i * 2 + 1][j];

-`

} } for (i = 0; i < height; i++) { for (j = width/2; j < width; j++) { if (i == 0) temp[i][j] = f_HPF[0] * dwt[i + 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i + 1][j]; else if (i > 0 && i < height-1) temp[i][j] = f_HPF[0] * dwt[i - 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i + 1][j]; else if (i == height-1) temp[i][j] = f_HPF[0] * dwt[i - 1][j] + f_HPF[1] * dwt[i][j] + f_HPF[2] * dwt[i - 1][j]; } } for (i = 0; i < height; i++) { for (j = width/2; j < width; j++) { temp1[i +height/2][j] = temp[i * 2][j]; } } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { dwt[i][j] = temp1[i][j]; } } } if (flag == 2)//vertical direction { for (i = 0; i < height/2; i++) { for (j = 0; j < width; j++) { if (j == 0) temp[i][j] = f_LPF[0] * org[i][j + 2] + f_LPF[1] * org[i][j + 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2]; else if (j == 1) temp[i][j] = f_LPF[0] * org[i][j] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2]; else if (j > 1 && j < height/2-2) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j + 2]; else if (j == height/2-2) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j + 1] + f_LPF[4] * org[i][j]; else if (j == height/2-1) temp[i][j] = f_LPF[0] * org[i][j - 2] + f_LPF[1] * org[i][j - 1] + f_LPF[2] * org[i][j] + f_LPF[3] * org[i][j - 1] + f_LPF[4] * org[i][j - 2]; } } for (i = 0; i < height/2; i++) { for (j = 0; j < width/4; j++)

小波变换C语言学习知识实现代码

-`#include#include#defineheight256#definewidth256voidtwoDDWT(doubleorg[][width],doubledwt[][width],intNumofBand);void
推荐度:
点击下载文档文档为doc格式
6eiam13kxx5gf8x599ez10e609m8f001b8d
领取福利

微信扫码领取福利

微信扫码分享