lioville
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:14 回覆:5 積分:3 註冊:2004-08-24
發送簡訊給我
|
請問前輩:
我在撰寫HARR小波轉換水平分割程式時出現問題 ![]() ,影像轉灰階後,進行小波水平分割,得到結果影像如圖。
< src="http://delphi.ktop.com.tw/loadfile.php?TOPICID=17826928&CC=398692">分割前, ![](http://delphi.ktop.com.tw/loadfile.php?TOPICID=17826615&CC=398685) 分割後(低頻的部分)。
我的疑問有兩點,(1)從分割後的影像看的出來低頻影像與原始有很大的差異,應該是要差不多才是(2)分割結果與原影像大小一樣大,應該會比較小才是。請高手解惑, 我的程式如下:
//----------------
if(OpenPictureDialog1->Execute())
{
Image1->AutoSize=true;
//Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); temp->LoadFromFile(OpenPictureDialog1->FileName);
temp->PixelFormat=pf24bit;
//----------轉灰階----------
int r,g,b;
int gray;
int i,j;
for(j=0;j Height;j++)
{
ptr = (Byte *)temp->ScanLine[j];
for(i=0;iWidth;i++)
{
b=ptr[i*3];
g=ptr[i*3+1];
r=ptr[i*3+2];
gray=0.299*r +0.587*g+0.114*b;
ptr[i*3]=(Byte)gray;
ptr[i*3+1]=(Byte)gray;
ptr[i*3+2]=(Byte)gray;
}
}
Image1->Picture->Assign(temp); ..........
//-----水平分割程式-----------
//-----設定灰階調色盤---------
typedef struct {
TLogPalette lPal;
TPaletteEntry dummy[256];
} LogPal; LogPal SysPal;
SysPal.lPal.palVersion = 0x300;
SysPal.lPal.palNumEntries = 256; for(int n=0;n<256;n++)
{
SysPal.lPal.palPalEntry[n].peRed = (unsigned char)n;
SysPal.lPal.palPalEntry[n].peGreen = (unsigned char)n;
SysPal.lPal.palPalEntry[n].peBlue = (unsigned char)n;
SysPal.lPal.palPalEntry[n].peFlags = 0;
} int W = temp->Width;
int H = temp->Height;
gray->PixelFormat=pf8bit;// 若設定為pf24bit輸出影像會變成原來的1/3大小
gray->Width=W;
gray->Height=H;
gray->Palette=CreatePalette(&SysPal.lPal); for(int i=0; iScanLine[i];
ptr1 = (Byte *)gray->ScanLine[i];
for(int j=0,k=0; jPicture->Assign(gray);
} 以上 初學者,請高手不吝指導, 謝謝
|
lioville
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:14 回覆:5 積分:3 註冊:2004-08-24
發送簡訊給我
|
引言:for(int i=0; i { ptr = (Byte *) temp->ScanLine[i];
ptr1 = (Byte *)gray->ScanLine[i];
for(int j=0,k=0; j { ptr1[k]=ptr[j*3]+ptr[j*3+3];
這段程式沒有貼好,應該是如下:
|
richtop
資深會員
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:122 回覆:646 積分:468 註冊:2003-06-10
發送簡訊給我
|
lioville 您好: 可愛的小女孩,應該讓她好看些。 ![]() 看了您的程式碼,在小波( class="code">void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{ int H, W, hW, value;
Byte *ptr, *ptr1; H = Image1->Picture->Height;
W = Image1->Picture->Width;
hW = W/2;
Image2->Picture->Bitmap->Height = H;
Image2->Picture->Bitmap->Width = W;
Image1->Picture->Bitmap->PixelFormat = pf24bit;
Image2->Picture->Bitmap->PixelFormat = pf24bit;
for (int i=0; i Picture->Bitmap->ScanLine[i]; // temp假設已轉成灰階
ptr1 = (Byte *) Image2->Picture->Bitmap->ScanLine[i]; // gray
for (int j=0,k=0; j RichTop 敬上 =====*****
把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題!
=====#####
|
lioville
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:14 回覆:5 積分:3 註冊:2004-08-24
發送簡訊給我
|
感謝richtop的指點,請問richtop大哥一般看常看到HARR小波轉換,針對其他基底的小波轉換,的程式撰寫上有沒有什ㄇ不同阿,還是感謝你答覆上個問題,謝謝
|
richtop
資深會員
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:122 回覆:646 積分:468 註冊:2003-06-10
發送簡訊給我
|
lioville 您好: 小波轉換其實就是拿訊號資料(含影像資料)與小波係數做convolution。以Haar小波來說,係數只有兩個,其他種類小波的係數可能更多,這時只是要做convolution的長度長一點,程式寫法類似(可以將小波係數存在陣列中,以for迴圈來作)。
垂直部分分解程式寫作的挑戰性更高,還有合成回來的部分,加油了!
不過利用Haar小波來實做,意義比較明確好懂,是個不錯的入門。 RichTop 敬上 =====*****
把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題!
=====#####
|