小波變換C語言實現(xiàn)代碼.doc_第1頁
小波變換C語言實現(xiàn)代碼.doc_第2頁
小波變換C語言實現(xiàn)代碼.doc_第3頁
小波變換C語言實現(xiàn)代碼.doc_第4頁
小波變換C語言實現(xiàn)代碼.doc_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

#include #include#define height 256#define width 256void twoDDWT(double orgwidth, double dwtwidth,int NumofBand);void oneDDWT(int flag, double orgwidth, double dwtwidth);void twoDIDWT(double dwtwidth, double recwidth,int NumofBand);void oneDIDWT(int flag, double dwtwidth, double recwidth);int main()int i, j;double orgheightwidth, dwtheightwidth,recheightwidth;FILE *lena;FILE *lena3; FILE *lena4;lena = fopen(c:lena.raw, rb);lena3 = fopen(c:lena3.raw, wb);lena4 = fopen(c:lena4.raw, wb);for (i = 0; i height; i+) for (j = 0; j width; j+)orgij = fgetc(lena);twoDDWT(org, dwt,4);for (i = 0; i height/2; i+)for (j = 0; j width/2; j+)orgij=dwtij;twoDDWT(org, dwt,7);for (i = 0; i height; i+)for (j = 0; j width; j+)fputc(dwtij, lena3);twoDIDWT(dwt, rec,7);for (i = 0; i height/2; i+)for (j = 0; j width/2; j+)dwtij=recij;twoDIDWT(dwt, rec,4);for (i = 0; i height; i+)for (j = 0; j width; j+)fputc(recij, lena4);return 0;void twoDDWT(double orgwidth, double dwtwidth,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 orgwidth, double dwtwidth)int i, j;double tempheightwidth, temp1heightwidth;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 1 & j height-2)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij + 1 + f_LPF4 * orgij + 2;else if (j = height-2)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij + 1 + f_LPF4 * orgij;else if (j = height-1)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij - 1 + f_LPF4 * orgij - 2;for (i = 0; i height; i+)for (j = 0; j width/2; j+)dwtij = tempij * 2 + 1;for (i = 0; i height; i+)for (j = 0; j 0 & j height-1)tempij = f_HPF0 * orgij - 1 + f_HPF1 * orgij + f_HPF2 * orgij + 1;else if (j = height-1)tempij = f_HPF0 * orgij - 1 + f_HPF1 * orgij + f_HPF2 * orgij - 1;for (i = 0; i height; i+)for (j = 0; j width/2; j+)dwtij + width/2 = tempij * 2;if (flag = 1)/horizontal directionfor (i = 0; i height; i+)for (j = 0; j 1 & i width-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwti + 2j;else if (i = width-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwtij;else if (i = width-1)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti - 1j + f_LPF4 * dwti - 2j;for (i = 0; i height; i+)for (j = 0; j width; j+)temp1ij = tempi * 2 + 1j;for (i = 0; i height; i+)for (j = 0; j 0 & i width-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti + 1j;else if (i = width-1)tempij = f_HPF0 *dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti - 1j;for (i = 0; i height; i+) for (j = 0; j width/2; j+)temp1ij+width/2 = tempi * 2j;for (i = 0; i height; i+)for (j = width/2; j 1 & i height-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwti + 2j;else if (i = height-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwtij;else if (i = height-1)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti - 1j + f_LPF4 * dwti - 2j;for (i = 0; i height; i+)for (j = width/2; j width; j+)temp1i+height/2j-width/2 = tempi * 2 + 1j;for (i = 0; i height; i+)for (j = width/2; j 0 & i height-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti + 1j;else if (i = height-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti - 1j;for (i = 0; i height; i+)for (j = width/2; j width; j+)temp1i +height/2j = tempi * 2j;for (i = 0; i height; i+)for (j = 0; j width; j+)dwtij = temp1ij;if (flag = 2)/vertical directionfor (i = 0; i height/2; i+)for (j = 0; j 1 & j height/2-2)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij + 1 + f_LPF4 * orgij + 2;else if (j = height/2-2)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij + 1 + f_LPF4 * orgij;else if (j = height/2-1)tempij = f_LPF0 * orgij - 2 + f_LPF1 * orgij - 1 + f_LPF2 * orgij + f_LPF3 * orgij - 1 + f_LPF4 * orgij - 2;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)dwtij = tempij * 2 + 1;for (i = 0; i height/2; i+)for (j = 0; j 0 & j height-1)tempij = f_HPF0 * orgij - 1 + f_HPF1 * orgij + f_HPF2 * orgij + 1;else if (j = height-1)tempij = f_HPF0 * orgij - 1 + f_HPF1 * orgij + f_HPF2 * orgij - 1;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)dwtij + width/4 = tempij * 2;if (flag = 3)/horizontal directionfor (i = 0; i height/2; i+)for (j = 0; j 1 & i height/2-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwti + 2j;else if (i = height/2-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwtij;else if (i = height/2-1)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti - 1j + f_LPF4 * dwti - 2j;for (i = 0; i height/4; i+)for (j = 0; j width/4; j+)temp1ij = tempi * 2 + 1j;for (i = 0; i height/2; i+)for (j = 0; j 0 & i height/2-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti + 1j;else if (i = height/2-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti - 1j;for (i = 0; i height/4; i+)for (j = 0; j width/4; j+)temp1i + height/4j = tempi * 2j;for (i = 0; i height/2; i+)for (j = width/4; j 1 & i height/2-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwti + 2j;else if (i = height/2-2)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti + 1j + f_LPF4 * dwtij;else if (i = height/2-1)tempij = f_LPF0 * dwti - 2j + f_LPF1 * dwti - 1j + f_LPF2 * dwtij + f_LPF3 * dwti - 1j + f_LPF4 * dwti - 2j;for (i = 0; i height/4; i+)for (j = width/4; j width/2; j+)temp1ij = tempi * 2 + 1j;for (i = 0; i height/2; i+)for (j = width/4; j 0 & i width/2-1)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti + 1j;else if (i = width/2)tempij = f_HPF0 * dwti - 1j + f_HPF1 * dwtij + f_HPF2 * dwti - 1j;for (i = 0; i height/4; i+)for (j = width/4; j width/2; j+)temp1i + height/4j = tempi * 2j; for (i = 0; i height/2; i+)for (j = 0; j width/2; j+)dwtij = temp1ij;void twoDIDWT(double dwtwidth, double recwidth,int NumofBand)if (NumofBand=7)oneDIDWT(2, dwt, rec);oneDIDWT(3, dwt, rec);if (NumofBand=4)oneDIDWT(1, dwt, rec);oneDIDWT(0, dwt, rec);void oneDIDWT(int flag, double dwtwidth, double recwidth)int i, j;double tempheightwidth, temp1heightwidth;double i_LPF = 0.5, 1, 0.5 ;double i_HPF = -0.125, -0.25, 0.75, -0.25, -0.125 ;if (flag = 2)/horizontal directionfor (i = 0; i height/2; i+)for (j = 0; j width/4; j+)if (i % 2 = 1)tempij = dwti / 2j;elsetempij = 0;for (i = 0; i height/2; i+)for (j = 0; j 0 & i height/2-1)recij = i_LPF0 * tempi - 1j + i_LPF1 * tempij + i_LPF2 * tempi + 1j;else if (i = height/2-1)recij = i_LPF0 * tempi - 1j + i_LPF1 * tempij + i_LPF2 * tempi - 1j;for (i = height/4; i height/2; i+)for (j = 0; j width/4; j+)dwti - height/4j = dwtij;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)if (i % 2 = 0)tempij = dwti / 2j;elsetempij = 0;for (i = 0; i height/2; i+)for (j = 0; j 1 & i height/2-2)temp1ij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi + 1j + i_HPF4 * tempi + 2j;else if (i = height/2-2)temp1ij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi + 1j + i_HPF4 * tempij;else if (i = height/2-1)temp1ij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi - 1j + i_HPF4 * tempi - 2j;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)recij = recij + temp1ij;for (i = 0; i height/4; i+)for (j = width/4; j width/2; j+)dwtij - height/4 = dwtij;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)if (i % 2 = 1)tempij = dwti / 2j;elsetempij = 0;for (i = 0; i height/2; i+)for (j = 0; j 0 & i height/2-1)temp1ij = i_LPF0 * tempi - 1j + i_LPF1 * tempij + i_LPF2 * tempi + 1j;else if (i = height/2-1)temp1ij = i_LPF0 * tempi - 1j + i_LPF1 * tempij + i_LPF2 * tempi - 1j;for (i = height/4; i height/2; i+)for (j = width/4; j width/2; j+)dwti - height/4j - width/4 = dwtij;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)if (i % 2 = 0)tempij = dwti / 2j;elsetempij = 0;for (i = 0; i height/2; i+)for (j = 0; j 1 & i height/2-2)dwtij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi + 1j + i_HPF4 * tempi + 2j;else if (i = height/2-2)dwtij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi + 1j + i_HPF4 * tempij;else if (i = height/2-1)dwtij = i_HPF0 * tempi - 2j + i_HPF1 * tempi - 1j + i_HPF2 * tempij + i_HPF3 * tempi - 1j + i_HPF4 * tempi - 2j;for (i = 0; i height/2; i+)for (j = 0; j width/4; j+)recij + width/4 = temp1ij + dwtij;if (flag = 3)/vertical directionfor (i = 0; i height/2; i+)for (j = 0; j width/2; j+)if (j % 2 = 1)tempij = recij / 2;elsetempij = 0;for (i = 0; i height/2; i+)for (j = 0; j 0 & j height/2-1)temp1ij = i_LPF0 * tempij - 1 + i_LPF1 * tempij + i_LPF2 * tempij + 1;else if (j = height/2-1)temp1ij = i_LPF0 * tempij - 1 + i_LPF1 * tempij + i_LPF

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論