線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1973
推到 Plurk!
推到 Facebook!

中間值濾波

尚未結案
enher
一般會員


發表:1
回覆:1
積分:0
註冊:2008-11-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-12-14 18:29:15 IP:118.167.xxx.xxx 訂閱
int left,right,low=0,up,down,i=0,temp;
int sort[9]={0};
Byte *ptr, *tptr,*uptr,*dptr;
for(int row = 1 ; row Picture->Bitmap->Height-1 ; row )
{
up=row-1;
down=row 1;

ptr = (Byte*) Image1->Picture->Bitmap->ScanLine[row]; //原始ptr
tptr = (Byte*) Image1->Picture->Bitmap->ScanLine[row]; //mask運算ptr
uptr = (Byte*) Image1->Picture->Bitmap->ScanLine[up]; //mask運算ptr
dptr = (Byte*) Image1->Picture->Bitmap->ScanLine[down]; //mask運算ptr

for(int col = 1 ; col < Image1->Picture->Bitmap->Width-1 ; col )
{
left=col-1;
right=col 1;
i=0;
sort[i]=uptr[left];
i ;
sort[i]=uptr[col];
i ;
sort[i]=uptr[right];
i ;
sort[i]=tptr[left];
i ;
sort[i]=tptr[col];
i ;
sort[i]=tptr[right];
i ;
sort[i]=dptr[left];
i ;
sort[i]=dptr[col];
i ;
sort[i]=dptr[right];
for(int j=0;j<9;j )
{
for(int k=j 1;k<9;k )
{

if(sort[k] {
temp=sort[j];
sort[j]=sort[k];
sort[k]=temp;
}
}
}
ptr[col]=sort[4];
}
}
Image1->Refresh();




以上是小弟寫的中間值濾波
但在執行時 圖片只有變過一次
但我不知道問題出在哪邊
請各位大大幫我解答一下
編輯記錄
enher 重新編輯於 2008-12-14 18:30:27, 註解 無‧
enher 重新編輯於 2008-12-14 18:31:52, 註解 無‧
enher
一般會員


發表:1
回覆:1
積分:0
註冊:2008-11-20

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-12-14 18:32:59 IP:118.167.xxx.xxx 訂閱
if(sort[k]<  sort[j]  )

不知道位啥這行沒顯示到...補上
編輯記錄
enher 重新編輯於 2008-12-14 18:33:43, 註解 無‧
mynameisoa
一般會員


發表:4
回覆:8
積分:2
註冊:2008-10-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-12-25 11:00:55 IP:163.13.xxx.xxx 訂閱

[code cpp]
int M[9];
//產生一臨時圖像以做Median
Graphics::TBitmap *MedianBmp= new Graphics::TBitmap();
MedianBmp->Assign(TempBitmap);
for(int y=0;yHeight;y ){
up =y-1;
down =y 1;
if(up<0) up = MedianBmp->Height-1;
if(down == MedianBmp->Height) down=0;
ptr = (Byte*)TempBitmap->ScanLine[y];
tptr = (Byte*)MedianBmp->ScanLine[y];
uptr= (Byte*)MedianBmp->ScanLine[up];
dptr= (Byte*)MedianBmp->ScanLine[down];
for(int x=0;xWidth;x ){
left = 3*x-1;
right= 3*x 1;
if(left<0) left = MedianBmp->Width-1;
if(right==MedianBmp->Width) right=0;
M[0]=(int)uptr[left];
M[1]=(int)uptr[3*x];
M[2]=(int)uptr[right];
M[3]=(int)tptr[left];
M[4]=(int)tptr[3*x];
M[5]=(int)tptr[right];
M[6]=(int)dptr[left];
M[7]=(int)dptr[3*x];
M[8]=(int)dptr[right];
for(int i=0 ; i<9 ; i ){
for(int j=i 1 ; j<9 ; j ){
if(M[i] < M[j]){
tmp = M[i];
M[i] = M[j];
M[j] = tmp;
}
}
}
ptr[3*x]=ptr[3*x 1]=ptr[3*x 2]=M[4];
}
}
delete MedianBmp;
[/code]

我想我們寫的差別在掃ScanLine我有另外開一張圖來做遮罩運算...

而你是直接在Image1上做

你這邊改掉看看
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-12-29 13:56:43 IP:60.251.xxx.xxx 訂閱
enher你好
你的中值濾波方式有誤
你不能一邊更改值,又一邊在你改過的值讀進來再做中值濾波
這樣的話,你所運算的值,就不是原本你要運算的資料了,而每次都會讀到被你改過的值(上一列及左邊)
你必須要各有一個input,output的地方
所以你應該
1. 和mynameisoa一樣,用兩個image來做,以image1為input,image2為output
2. 建立一塊buffer,先把image1的資料讀進buffer,並把對buffer作中值濾波的結果值寫回image1
系統時間:2024-04-20 11:50:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!