第一范文网 - 专业文章范例文档资料分享平台

小波变换C语言实现代码

来源:用户分享 时间:2025/5/26 5:08:57 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

#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语言实现代码 的文档
小波变换C语言实现代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6ka845ebdz6h1tx45d7638ccg96n4k006zl_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top