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

影像處理結果僅只有整張圖片的1/3

尚未結案
thielip
一般會員


發表:1
回覆:2
積分:0
註冊:2007-04-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-04-25 23:39:32 IP:163.13.xxx.xxx 訂閱
小弟在進行圖片連續處理去建構出適應性背景處理 但是建構出來的背景 只有整張圖片的1/3 我想  應該是我的程式在處理過程中 只有處理到一個BYTE  並沒有處理到3個BYTE 但是我不知道我哪邊少寫了 可以請板上的大大幫忙解決嗎    這張圖是跑到第1500張後的現實影像 http://www.wretch.cc/album/show.php?i=swimaman&b=3&f=1312318441&p=0    這張是從第一張建構到第1500張的背景資料 http://www.wretch.cc/album/show.php?i=swimaman&b=3&f=1312318441&p=1 其中Image1為建構出的背景 Image2為處理的現實圖片    <textarea class="cpp" rows="10" cols="60" name="code"> //Adaptive Background Update if (OpenDialog2->Execute()) for (int a = 1; a < 1500; a ) { Image2->Picture->LoadFromFile(IntToStr(a) ".bmp"); Form1->Caption=IntToStr(a) ".bmp"; byte **ptrr, **ptr1r,**ptrg, **ptr1g,**ptrb, **ptr1b, **r,**g,**b; int histogramR[256],histogramG[256],histogramB[256],max_valueR, max_pixelR; int max_valueG, max_pixelG,max_valueB, max_pixelB; //初始 for(int i = 0; i < 256; i ) { histogramR[i] = 0; histogramG[i] = 0; histogramB[i] = 0; } Graphics::TBitmap *pBitmap=new Graphics::TBitmap; Graphics::TBitmap *pBitmap1=new Graphics::TBitmap; pBitmap->Assign(Image1->Picture->Bitmap); pBitmap1->Assign(Image2->Picture->Bitmap); ptrr = new byte*[pBitmap->Height]; ptr1r = new byte*[pBitmap1->Height]; ptrg = new byte*[pBitmap->Height]; ptr1g = new byte*[pBitmap1->Height]; ptrb = new byte*[pBitmap->Height]; ptr1b = new byte*[pBitmap1->Height]; r = new byte*[pBitmap1->Height]; g = new byte*[pBitmap1->Height]; b = new byte*[pBitmap1->Height]; for (int y = 0; y < pBitmap->Height; y ) { ptrr[y] = (Byte *)pBitmap->ScanLine[y]; ptr1r[y] = (Byte *)pBitmap1->ScanLine[y]; ptrg[y] = (Byte *)pBitmap->ScanLine[y]; ptr1g[y] = (Byte *)pBitmap1->ScanLine[y]; ptrb[y] = (Byte *)pBitmap->ScanLine[y]; ptr1b[y] = (Byte *)pBitmap1->ScanLine[y]; r[y] = new byte[pBitmap1-> Width]; g[y] = new byte[pBitmap1-> Width]; b[y] = new byte[pBitmap1-> Width]; for (int x = 0; x < pBitmap->Width; x ) { //相減 r[y][x] = abs(ptrr[y][x] - ptr1r[y][x]); g[y][x] = abs(ptrg[y][x] - ptr1g[y][x]); b[y][x] = abs(ptrb[y][x] - ptr1b[y][x]); } } for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { histogramR[r[y][x]] ; histogramG[g[y][x]] ; histogramB[b[y][x]] ; } //找尖峰,取第一個小於尖峰1/10之灰度值當作門檻值 max_valueR = 0; max_valueG = 0; max_valueB = 0; for(int i = 0; i < 256; i ) { if(histogramR[i] > max_valueR) { max_valueR = histogramR[i]; max_pixelR = i; } if(histogramG[i] > max_valueG) { max_valueG = histogramG[i]; max_pixelG = i; } if(histogramB[i] > max_valueB) { max_valueB = histogramB[i]; max_pixelB = i; } } do { max_pixelR ; } while(histogramR[max_pixelR] > (max_valueR/10) ); for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(r[y][x] > max_pixelR) { r[y][x] = 255; } else { r[y][x] = 0; } } do { max_pixelG ; } while(histogramG[max_pixelG] > (max_valueG/10) ); for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(g[y][x] > max_pixelG) { g[y][x] = 255; } else { g[y][x] = 0; } } do { max_pixelB ; } while(histogramB[max_pixelR] > (max_valueB/10) ); for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(b[y][x] > max_pixelB) { b[y][x] = 255; } else { b[y][x] = 0; } } //若為0,取current image 若為255 取current background for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(r[y][x] == 0) { r[y][x] = ptr1r[y][x]; } else { r[y][x] = ptrr[y][x]; } } for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(g[y][x] == 0) { g[y][x] = ptr1g[y][x]; } else { g[y][x] = ptrg[y][x]; } } for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { if(b[y][x] == 0) { b[y][x] = ptr1b[y][x]; } else { b[y][x] = ptrb[y][x]; } } //更新 0.1為權重 for (int y = 0; y < pBitmap->Height; y ) for (int x = 0; x < pBitmap->Width; x ) { ptrr[y][x] = (0.1*r[y][x]) (0.9*ptrr[y][x]); ptrg[y][x] = (0.1*g[y][x]) (0.9*ptrg[y][x]); ptrb[y][x] = (0.1*b[y][x]) (0.9*ptrb[y][x]); } Image1->Picture->Bitmap->Assign(pBitmap); StatusBar1->Panels->Items[2]->Text="門檻值" IntToStr(max_pixelR); StatusBar1->Panels->Items[3]->Text="門檻值" IntToStr(max_pixelG); StatusBar1->Panels->Items[4]->Text="門檻值" IntToStr(max_pixelB); for (int y = 0; y < pBitmap1->Height; y ) { delete r[y]; delete g[y]; delete b[y]; } delete r; delete g; delete b; delete pBitmap; delete pBitmap1; Application->ProcessMessages(); } </textarea>
taishyang
站務副站長


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-04-26 09:39:39 IP:122.124.xxx.xxx 未訂閱
請指定Bitmap的PixelFormat=pf24bit
編輯記錄
taishyang 重新編輯於 2007-04-26 09:41:10, 註解 加上 = pf24bit ‧
thielip
一般會員


發表:1
回覆:2
積分:0
註冊:2007-04-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-04-27 17:49:59 IP:163.13.xxx.xxx 訂閱

taishyang大大您好

我於程式的23.24行加入

Bitmap->PixelFormat=pf24bit;
Bitmap1->PixelFormat=pf24bit;

結果還是僅只有處理整張圖片的 1/3
有可能是別的地方有出錯嗎



===================引 用 taishyang 文 章===================
請指定Bitmap的PixelFormat=pf24bit



taishyang
站務副站長


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-04-27 18:04:19 IP:122.124.xxx.xxx 未訂閱
我沒有仔細看你的程式碼, 通常只處理1/3表示你取RGB的值有問題
pixelformat為24bits BMP像素排列為BGRBGRBGR...所以取RGB的時候每次要位移3

但假如你的source的pixelformat是8bits bmp,則沒有要位移3的問題

原因同下面連結
http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=38760

===================引 用 thielip 文 章===================

taishyang大大您好

我於程式的23.24行加入

Bitmap->PixelFormat=pf24bit;
Bitmap1->PixelFormat=pf24bit;

結果還是僅只有處理整張圖片的 1/3
有可能是別的地方有出錯嗎



===================引 用 taishyang 文 章===================
請指定Bitmap的PixelFormat=pf24bit



編輯記錄
taishyang 重新編輯於 2007-04-27 18:06:17, 註解 無‧
taishyang 重新編輯於 2007-04-27 18:16:03, 註解 加入連結‧
暗黑破壞神
版主


發表:9
回覆:2301
積分:1627
註冊:2004-10-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-04-27 18:12:03 IP:218.170.xxx.xxx 未訂閱
我是懷疑你 RGB 中只拿了一個的長度出來處理。
我記得以前我也犯過這樣的錯。
可是我又沒時間幫你看程式。只能回想一下自己的經驗這樣跟你說。
thielip
一般會員


發表:1
回覆:2
積分:0
註冊:2007-04-18

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-04-28 12:06:09 IP:220.132.xxx.xxx 訂閱
感謝 taishyang 大大的提醒
我想我應該可以解決我的問題~
我處理成功的話 會把程式碼重新貼上的



===================引 用 taishyang 文 章===================
我沒有仔細看你的程式碼, 通常只處理1/3表示你取RGB的值有問題
pixelformat為24bits BMP像素排列為BGRBGRBGR...所以取RGB的時候每次要位移3

但假如你的source的pixelformat是8bits bmp,則沒有要位移3的問題

原因同下面連結
???? http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=38760

===================引 用 thielip 文 章===================

taishyang大大您好

我於程式的23.24行加入

Bitmap->PixelFormat=pf24bit;
Bitmap1->PixelFormat=pf24bit;

結果還是僅只有處理整張圖片的 1/3
有可能是別的地方有出錯嗎



===================引 用 taishyang 文 章===================
請指定Bitmap的PixelFormat=pf24bit



系統時間:2024-05-03 1:13:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!