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

影像標籤化的問題

尚未結案
chtsai1025
一般會員


發表:6
回覆:3
積分:1
註冊:2010-02-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-02-16 20:58:54 IP:140.113.xxx.xxx 訂閱
很抱歉是同一題,不過本來的題目它掛點了
所以我在PO一次

各位前輩
最近用影像處理在擷取紅色目標物的圖
並且加上標籤
不過在同一塊的紅色圖上
卻會出現不同數目的標籤
如圖所示


下面會附上我標籤化的程式
請問各位前輩
這樣的問題會是出在哪裡?
該怎麼解決呢?

謝謝



[code cpp]

int Label=1;
// 標籤Frame初始化
for(int Row=0;Row for(int Col=0;Col ColorBufOrgn_Labeling[Row][Col] = 0;
}
}
// 標籤法演算法(3*3)
// 尋找方向如下:
// → → →
// ↑ ↓
// ← ← ↓
for(int Row=1;Row for(int Col=1;Col if(ColorBufOrgn[Row][Col][2] == 255){
// 周圍如果也是紅色,且有非零的標籤值,就將標籤值給中間的
if((ColorBufOrgn[Row-1][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col-1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col-1];}
else if((ColorBufOrgn[Row-1][Col][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col];}
else if((ColorBufOrgn[Row-1][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col 1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col 1];}
else if((ColorBufOrgn[Row][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row][Col 1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row][Col 1];}
else if((ColorBufOrgn[Row 1][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col 1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col 1];}
else if((ColorBufOrgn[Row 1][Col][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col];}
else if((ColorBufOrgn[Row 1][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col-1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col-1];}
else if((ColorBufOrgn[Row][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row][Col-1] != 0))
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row][Col-1];}

// 唯一能更改標籤的地方
else{ColorBufOrgn_Labeling[Row][Col] = Label; Label ;}

}
}
}
//這裡進行再過濾,防止誤判
//透過這個,可以確保一整個區塊的標籤都是同樣的
for(int Row=1;Row for(int Col=1;Col // 如果MASK內全部都有標籤
if( (ColorBufOrgn_Labeling[Row-1][Col-1] != 0)&&(ColorBufOrgn_Labeling[Row][Col-1] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col-1] != 0)&&
(ColorBufOrgn_Labeling[Row-1][Col ] != 0)&&(ColorBufOrgn_Labeling[Row][Col ] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col ] != 0)&&
(ColorBufOrgn_Labeling[Row-1][Col 1] != 0)&&(ColorBufOrgn_Labeling[Row][Col 1] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col 1] != 0)){
// 檢查是不是每個Label都相同,只要有一個不同就會處理
if( (ColorBufOrgn_Labeling[Row-1][Col-1] != ColorBufOrgn_Labeling[Row ][Col-1])||
(ColorBufOrgn_Labeling[Row ][Col-1] != ColorBufOrgn_Labeling[Row 1][Col-1])||
(ColorBufOrgn_Labeling[Row 1][Col-1] != ColorBufOrgn_Labeling[Row-1][Col ])||
(ColorBufOrgn_Labeling[Row-1][Col ] != ColorBufOrgn_Labeling[Row ][Col ])||
(ColorBufOrgn_Labeling[Row ][Col ] != ColorBufOrgn_Labeling[Row 1][Col ])||
(ColorBufOrgn_Labeling[Row 1][Col ] != ColorBufOrgn_Labeling[Row-1][Col 1])||
(ColorBufOrgn_Labeling[Row-1][Col 1] != ColorBufOrgn_Labeling[Row ][Col 1])||
(ColorBufOrgn_Labeling[Row ][Col 1] != ColorBufOrgn_Labeling[Row 1][Col 1]) ){
// 檢查裡面有沒有1
if( (ColorBufOrgn_Labeling[Row-1][Col-1] == 1)||(ColorBufOrgn_Labeling[Row][Col-1] == 1)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 1)||
(ColorBufOrgn_Labeling[Row-1][Col ] == 1)||(ColorBufOrgn_Labeling[Row][Col ] == 1)||(ColorBufOrgn_Labeling[Row 1][Col ] == 1)||
(ColorBufOrgn_Labeling[Row-1][Col 1] == 1)||(ColorBufOrgn_Labeling[Row][Col 1] == 1)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 1)){
ColorBufOrgn_Labeling[Row-1][Col-1] = 1;
ColorBufOrgn_Labeling[Row ][Col-1] = 1;
ColorBufOrgn_Labeling[Row 1][Col-1] = 1;
ColorBufOrgn_Labeling[Row-1][Col ] = 1;
ColorBufOrgn_Labeling[Row ][Col ] = 1;
ColorBufOrgn_Labeling[Row 1][Col ] = 1;
ColorBufOrgn_Labeling[Row-1][Col 1] = 1;
ColorBufOrgn_Labeling[Row ][Col 1] = 1;
ColorBufOrgn_Labeling[Row 1][Col 1] = 1;
}
// 檢查有沒有2
else if((ColorBufOrgn_Labeling[Row-1][Col-1] == 2)||(ColorBufOrgn_Labeling[Row][Col-1] == 2)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 2)||
(ColorBufOrgn_Labeling[Row-1][Col ] == 2)||(ColorBufOrgn_Labeling[Row][Col ] == 2)||(ColorBufOrgn_Labeling[Row 1][Col ] == 2)||
(ColorBufOrgn_Labeling[Row-1][Col 1] == 2)||(ColorBufOrgn_Labeling[Row][Col 1] == 2)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 2)){
ColorBufOrgn_Labeling[Row-1][Col-1] = 2;
ColorBufOrgn_Labeling[Row ][Col-1] = 2;
ColorBufOrgn_Labeling[Row 1][Col-1] = 2;
ColorBufOrgn_Labeling[Row-1][Col ] = 2;
ColorBufOrgn_Labeling[Row ][Col ] = 2;
ColorBufOrgn_Labeling[Row 1][Col ] = 2;
ColorBufOrgn_Labeling[Row-1][Col 1] = 2;
ColorBufOrgn_Labeling[Row ][Col 1] = 2;
ColorBufOrgn_Labeling[Row 1][Col 1] = 2;
}
// 只要一個區域內有非0非1非2的標籤, 直接判定為3
else /*if((ColorBufOrgn_Labeling[Row-1][Col-1] == 3)||(ColorBufOrgn_Labeling[Row][Col-1] == 3)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 3)||
(ColorBufOrgn_Labeling[Row-1][Col ] == 3)||(ColorBufOrgn_Labeling[Row][Col ] == 3)||(ColorBufOrgn_Labeling[Row 1][Col ] == 3)||
(ColorBufOrgn_Labeling[Row-1][Col 1] == 3)||(ColorBufOrgn_Labeling[Row][Col 1] == 3)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 3))*/{
ColorBufOrgn_Labeling[Row-1][Col-1] = 3;
ColorBufOrgn_Labeling[Row ][Col-1] = 3;
ColorBufOrgn_Labeling[Row 1][Col-1] = 3;
ColorBufOrgn_Labeling[Row-1][Col ] = 3;
ColorBufOrgn_Labeling[Row ][Col ] = 3;
ColorBufOrgn_Labeling[Row 1][Col ] = 3;
ColorBufOrgn_Labeling[Row-1][Col 1] = 3;
ColorBufOrgn_Labeling[Row ][Col 1] = 3;
ColorBufOrgn_Labeling[Row 1][Col 1] = 3;
}
}
}
}
}



[/code]

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