全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3418
推到 Plurk!
推到 Facebook!

想請問如何做出wavelet三階反轉換?

尚未結案
naterobinson
一般會員


發表:2
回覆:0
積分:0
註冊:2015-09-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2015-09-21 15:01:16 IP:140.123.xxx.xxx 訂閱
以下附檔壓縮檔是wavelet三階轉換的project1, 由於window無法讀檔,所以我使用im player去讀圖檔

我已經可做出三階的轉換,問題出在它反轉換呢?

為何反轉換回來出來的圖會誤差這麼大呢? 它的值會爆掉!

是哪理出了問題呢?

以下是.cpp code:


#include "resource.h"
#include "wavelet_program.h"

typedef unsigned char BYTE;
typedef unsigned short int UINT16;
typedef long UINT32;

float table_index_a[9]={-4,-3,-2,-1,0,1,2,3,4};
float table_context_a[9]={
0.026748757410810,
-0.016864118442875,
-0.078223266528990,
0.266864118442875,
0.602949018236360,
0.266864118442875,
-0.078223266528990,
-0.016864118442875,
0.026748757410810
};

float table_index_b[7]={-2,-1,0,1,2,3,4};
float table_context_b[7]={
0.045635881557125,
-0.02877176311425,
-0.295635881557125,
0.5575435262285,
-0.295635881557125,
-0.02877176311425,
0.045635881557125
};
//以上為9/7多貝西濾波器係數

float table_index_c[3]={-1,0,1};
float table_context_c[3]={
-0.02877176311425,
0.5575435262285,
-0.02877176311425
};

float table_index_d[4]={-1,0,1,2};
float table_context_d[4]={
0.016864118442875,
-0.266864118442875,
-0.266864118442875,
0.016864118442875
};

float table_index_e[4]={-2,-1,0,1};
float table_context_e[4]={
-0.045635881557125,
0.295635881557125,
0.295635881557125,
-0.045635881557125
};
float table_index_f[5]={-2,-1,0,1,2};
float table_context_f[5]={
0.026748757410810,
-0.078223266528990,
0.602949018236360,
-0.078223266528990,
0.026748757410810
};


void transrows( BYTE **dest, BYTE **sour, unsigned int w, unsigned int h)//w 為設定好的影像寬 h為長 dest 為此子程式的輸出 sour在此為協助子程式計算
{

int n;
float s, d;
unsigned int w2 = w / 2;

for (unsigned int y = 0; y < h; y ) {
for (unsigned int k = 0; k < w2; k ) {

s = 0.0f;
d = 0.0f;//一維陣列
//m=-4,-3,-2,-1,0,1,2,3,4
for (int m = table_index_a[0]; m <= table_index_a[8]; m ) {
n = 2 * k m;//每個k產生的n會變動9次
if (n < 0) n = 0 - n;
if (n >= (int)w)//k approach w2
n -= 2 * (1 n - w);//n*=-n 2w-2 新n會逼近w w壓制n的範圍
//m 4= 0 1 2 4 5 6 7 8
s = table_context_a[m 4] * float(sour[y][n]);// m上升 一個點和左右八位置配合係數加9次
}
//m=--2,-1,0,1,2,3,4
for (int m = table_index_b[0]; m <= table_index_b[6]; m ) {
n = 2 * k m;//每個k產生的n會變動7次
if (n < 0) n = 0 - n;
if (n >= (int)w)
n -= 2 * (1 n - w);
//m 2= 0 1 2 3 4 5 6
d = table_context_b[m 2]* float(sour[y][n]);//m上升 一個點和左右七個位置配合係數加7次
}

dest[y][k] = s;
dest[y][k w2] = d;//把上述求出代入dest的 左半部(低頻)和右半部(高頻) 圖像寬會只剩一半
}//w2
}//y

}

void transcols(BYTE** dest, BYTE** sour, unsigned int w, unsigned int h)
{
int n;
float s, d;
unsigned int h2 = h / 2;


for (unsigned int x = 0; x < w; x ) {
for (unsigned int k = 0; k < h2; k ) {

s = 0.0f;
d = 0.0f;

for (int m = table_index_a[0]; m <= table_index_a[8]; m ) {
n = 2 * k m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);
s = table_context_a[m 4] * float(sour[n][x]);
}
for (int m = table_index_b[0]; m <= table_index_b[6]; m ) {
n = 2 * k m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);
d = table_context_b[m 2] * float(sour[n][x]);
}

if (x< w/2 )
dest[k][x] = s;
else
dest[k][x] = s;

dest[k h2][x] = d; //集中低頻
}//h2
}//x


}

void synthcols(BYTE** dest, BYTE** sour, unsigned int w, unsigned int h)
{
int n;
float s2k, s2k1;

for (unsigned int x = 0; x < 2*w; x ) {
for (unsigned int k = 0; k < h; k ) {

s2k = 0;
s2k1 = 0;
//m= -1 0 1
for (int m = table_index_c[0]; m<=table_index_c[2]; m )
{ //s2k even H
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);

s2k = table_context_c[m 1] * float(sour[n][x]);
}
//m= -1 0 1 2
for (int m = table_index_d[0]; m <= table_index_d[3]; m ) { //s2k even G
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);
s2k = table_context_d[m 1] * float(sour[n h][x]);
}

for (int m = table_index_e[0]; m <= table_index_e[3]; m ) { //s2k1 odd H
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);
s2k1 = table_context_e[m 2] * float(sour[n][x]);
}
for (int m = table_index_f[0]; m <= table_index_f[4]; m ) { //s2k1 odd G
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)h) n -= 2 * (1 n - h);
s2k1 = table_context_f[m 2] * float(sour[n h][x]);
}

dest[2*k][x] = 2.0f * s2k;
dest[2*k 1][x] = 2.0f * s2k1;
}
}

}

void synthrows(BYTE** dest, BYTE** sour, unsigned int w, unsigned int h) //w,h of the LO part
{
int n;
float s2k, s2k1;

for (unsigned int y = 0; y < 2*h; y ) {
for (unsigned int k = 0; k < w; k ) {

s2k = 0.0f;
s2k1 = 0.0f;

for (int m = table_index_c[0]; m <= table_index_c[2]; m ) { //s2k even H
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)w) n -= 2 * (1 n - w);

s2k = table_context_c[m 1] * float(sour[y][n]);
}
for (int m = table_index_d[0]; m <= table_index_d[3]; m ) { //s2k even G
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)w) n -= 2 * (1 n - w);
s2k = table_context_d[m 1] * float(sour[y][n w]);
}

for (int m = table_index_e[0]; m <= table_index_e[3]; m ) { //s2k1 odd H
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)w) n -= 2 * (1 n - w);
s2k1 = table_context_e[m 2] * float(sour[y][n]);
}
for (int m = table_index_f[0]; m <= table_index_f[4]; m ) { //s2k1 odd G
n = k - m;
if (n < 0) n = 0 - n;
if (n >= (int)w) n -= 2 * (1 n - w);
s2k1 = table_context_f[m 2] * float(sour[y][n w]);
}

//dest[y][2*k] = (2.0f * s2k) .5;
//dest[y][2*k 1] = (2.0f * s2k1) .5;
dest[y][2*k] = mmxround(2.0f * s2k);
dest[y][2*k 1] = mmxround(2.0f * s2k1);
}
}
}

inline char mmxround(float f)
{
char c[8] = {0, 0, 0, 0, 0, 0, 0, 0};
__m64 *mc = (__m64 *)c;

__m128 mf = _mm_load_ss(&f);
*mc = _mm_cvtps_pi8(mf);

_mm_empty();

return c[0];
}
編輯記錄
naterobinson 重新編輯於 2015-09-21 15:41:50, 註解 無‧
naterobinson 重新編輯於 2015-09-21 15:42:13, 註解 無‧
naterobinson 重新編輯於 2015-09-21 16:35:23, 註解 無‧
naterobinson 重新編輯於 2015-09-21 16:36:00, 註解 無‧
naterobinson 重新編輯於 2015-09-21 16:45:09, 註解 無‧
naterobinson 重新編輯於 2015-09-21 16:47:43, 註解 無‧
naterobinson 重新編輯於 2015-09-23 15:00:33, 註解 無‧
naterobinson 重新編輯於 2015-09-24 15:39:28, 註解 無‧
系統時間:2024-11-21 16:57:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!