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

sobel問題.. 畫面只有呈現一半

尚未結案
michael081906
一般會員


發表:2
回覆:3
積分:1
註冊:2010-08-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-09-27 19:58:53 IP:124.8.xxx.xxx 訂閱
各位前輩好,小弟目前要做影像sobel的處理,跑出來的成果卻是約一半的灰階影像和一半的sobel影像...

而且sobel的區域會有粉紅色的線條,請問各位前輩這是什麼狀況..?

以下是我的程式碼... 謝謝
[code cpp]
void __fastcall TForm1::Sobel1Click(TObject *Sender)
{
Graphics::TBitmap *Bmp, *temp ;
TRGBTriple *pptr,*ppptr;
BYTE gray;
int i, j;
Bmp->PixelFormat=pf24bit;
Bmp=Image1->Picture->Bitmap;

temp = new Graphics::TBitmap();
temp->PixelFormat=pf24bit;
temp->Height = Bmp->Height;
temp->Width = Bmp->Width;


for (j=0; jHeight; j )
{
pptr = (TRGBTriple *)Bmp->ScanLine[j];
ppptr = (TRGBTriple *)temp->ScanLine[j];
for (i=0; iWidth; i )
{
gray = (BYTE)( (pptr[i].rgbtRed*0.299) (pptr[i].rgbtGreen*0.587) (pptr[i].rgbtBlue*0.114) );

ppptr[i].rgbtRed = gray;
ppptr[i].rgbtGreen = gray;
ppptr[i].rgbtBlue = gray;
}
}
Bmp->Assign(temp);


Byte *ptr=NULL, *tptr, *uptr, *dptr;
int up, down ,left,right,GX,GY,H,W;

Graphics::TBitmap *TheBitmap, *TempBitmap,*OrgBitmap;
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->PixelFormat=pf24bit;

TempBitmap= new Graphics::TBitmap();
TempBitmap->PixelFormat=pf24bit;
TempBitmap->Height = Image1->Height;
TempBitmap->Width = Image1->Width;
TempBitmap->Assign(TheBitmap);

OrgBitmap= new Graphics::TBitmap();
OrgBitmap->Height = Image1->Height;
OrgBitmap->Width = Image1->Width;
OrgBitmap->PixelFormat=pf24bit;


for(int y=0;yHeight;y )
{ up=y-1;
down=y 1;
if(up<0) up=TheBitmap->Height-1;
if(down==TheBitmap->Height) down=0;
ptr=(Byte*)TheBitmap->ScanLine[y];
tptr=(Byte*)TempBitmap->ScanLine[y];
uptr=(Byte*)TempBitmap->ScanLine[up];
dptr=(Byte*)TempBitmap->ScanLine[down];
for(int x=0;xWidth;x )
{ left=x-1;
right=x 1;

if(left<0) left=TheBitmap->Width-1;
if(right==TheBitmap->Width) right=0;
GX=(int)(uptr[left] uptr[x]*2 uptr[right]-dptr[left]-dptr[x]*2-dptr[right]);
GY=(int)(-uptr[left]-tptr[left]*2-dptr[left] uptr[right] tptr[right]*2 dptr[right]);
int ss=sqrt(pow(GX,2) pow(GY,2));
if (ss>255) ss=255;
if (ss<0) ss=0;
ptr[x]=ss;
}
}
delete TempBitmap;
Repaint();
TheBitmap->Assign(TheBitmap);
}

[/code]

編輯記錄
michael081906 重新編輯於 2010-09-27 20:41:12, 註解 無‧
michael081906 重新編輯於 2010-09-27 20:58:15, 註解 把Bmp的pixelformat往上移到載入圖檔的前面‧
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-09-27 20:26:20 IP:122.116.xxx.xxx 訂閱
Bmp有設定pixelformat嗎?
michael081906
一般會員


發表:2
回覆:3
積分:1
註冊:2010-08-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-09-27 20:38:13 IP:124.8.xxx.xxx 訂閱
我引用過後還是一樣的問題耶..


===================引 用 taishyang 文 章===================
Bmp有設定pixelformat嗎?
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-09-27 20:41:37 IP:122.116.xxx.xxx 訂閱
引用?
修改後的程式長什麼樣?
michael081906
一般會員


發表:2
回覆:3
積分:1
註冊:2010-08-10

發送簡訊給我
#5 引用回覆 回覆 發表時間:2010-09-27 20:45:35 IP:124.8.xxx.xxx 訂閱
呃...不就是加上XXX->pixelFormat=pf24bit嗎??
我已經在上面的程式碼修改過了
OrBitmap ,TempBitmap等等都有加了...



===================引 用 taishyang 文 章===================
引用?
修改後的程式長什麼樣?
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#6 引用回覆 回覆 發表時間:2010-09-27 20:52:57 IP:122.116.xxx.xxx 訂閱
載入內容前設定,跟載入內容後設定結果會不同

michael081906
一般會員


發表:2
回覆:3
積分:1
註冊:2010-08-10

發送簡訊給我
#7 引用回覆 回覆 發表時間:2010-09-27 21:02:48 IP:124.8.xxx.xxx 訂閱
我把它改成載入之前設定...可是結果一樣QQ..


[code cpp]

void __fastcall TForm1::Sobel1Click(TObject *Sender)
{
Graphics::TBitmap *Bmp, *temp ;
TRGBTriple *pptr,*ppptr;
BYTE gray;
int i, j;
Bmp = new Graphics::TBitmap();
Bmp->PixelFormat=pf24bit;
Bmp=Image1->Picture->Bitmap;

temp = new Graphics::TBitmap();
temp->PixelFormat=pf24bit;
temp->Height = Bmp->Height;
temp->Width = Bmp->Width;


for (j=0; jHeight; j )
{
pptr = (TRGBTriple *)Bmp->ScanLine[j];
ppptr = (TRGBTriple *)temp->ScanLine[j];
for (i=0; iWidth; i )
{
gray = (BYTE)( (pptr[i].rgbtRed*0.299) (pptr[i].rgbtGreen*0.587) (pptr[i].rgbtBlue*0.114) );

ppptr[i].rgbtRed = gray;
ppptr[i].rgbtGreen = gray;
ppptr[i].rgbtBlue = gray;
}
}
Bmp->Assign(temp);


Byte *ptr=NULL, *tptr, *uptr, *dptr;
int up, down ,left,right,GX,GY,H,W;

Graphics::TBitmap *TheBitmap, *TempBitmap,*OrgBitmap;
TheBitmap= new Graphics::TBitmap();
TheBitmap->PixelFormat=pf24bit;
TheBitmap=Image1->Picture->Bitmap;

TempBitmap= new Graphics::TBitmap();
TempBitmap->Height = Image1->Height;
TempBitmap->Width = Image1->Width;
TempBitmap->PixelFormat=pf24bit;
TempBitmap->Assign(TheBitmap);
OrgBitmap= new Graphics::TBitmap();
OrgBitmap->Height = Image1->Height;
OrgBitmap->Width = Image1->Width;
OrgBitmap->PixelFormat=pf24bit;


for(int y=0;yHeight;y )
{ up=y-1;
down=y 1;
if(up<0) up=TheBitmap->Height-1;
if(down==TheBitmap->Height) down=0;
ptr=(Byte*)TheBitmap->ScanLine[y];
tptr=(Byte*)TempBitmap->ScanLine[y];
uptr=(Byte*)TempBitmap->ScanLine[up];
dptr=(Byte*)TempBitmap->ScanLine[down];
for(int x=0;xWidth;x )
{ left=x-1;
right=x 1;

if(left<0) left=TheBitmap->Width-1;
if(right==TheBitmap->Width) right=0;
GX=(int)(uptr[left] uptr[x]*2 uptr[right]-dptr[left]-dptr[x]*2-dptr[right]);
GY=(int)(-uptr[left]-tptr[left]*2-dptr[left] uptr[right] tptr[right]*2 dptr[right]);
int ss=sqrt(pow(GX,2) pow(GY,2));
if (ss>255) ss=255;
if (ss<0) ss=0;
ptr[x]=ss;
}
}
delete TempBitmap;
Repaint();
TheBitmap->Assign(TheBitmap);
}

[/code]



===================引 用 taishyang 文 章===================
載入內容前設定,跟載入內容後設定結果會不同

編輯記錄
michael081906 重新編輯於 2010-09-27 21:04:46, 註解 貼錯...= = 抱歉‧
michael081906 重新編輯於 2010-09-27 21:05:29, 註解 無‧
michael081906 重新編輯於 2010-09-27 21:06:23, 註解 無‧
系統時間:2024-03-29 0:47:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!