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

尚未結案
chtsai1025
一般會員


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-02-17 11:07:54 IP:140.113.xxx.xxx 訂閱

[code cpp]



請在此區域// ← ← ↓
for(int Row=1;Row for(int Col=1;Col if(ColorBufOrgn[Row][Col][2] == 255){
// 周圍如果也是紅色,且有非零的標籤值,就將標籤值給中間的
if( (ColorBufOrgn[Row-1][Col-1][2] == 0)&&
(ColorBufOrgn[Row-1][Col][2] == 0)&&
(ColorBufOrgn[Row-1][Col 1][2] == 0)&&
(ColorBufOrgn[Row][Col-1][2] == 0))
{ColorBufOrgn_Labeling[Row][Col] = Label;
Label ;}
else if(ColorBufOrgn[Row-1][Col-1][2] == 255)
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col-1];}

else if(ColorBufOrgn[Row-1][Col][2] == 255)
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col];}

else if(ColorBufOrgn[Row-1][Col 1][2] == 255)
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col=1];}

else if(ColorBufOrgn[Row][Col-1][2] == 255)
{ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row][Col-1];}

else{ }

}
}
}

//這裡進行再過濾,防止誤判
//透過這個,可以確保一整個區塊的標籤都是同樣的
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;
}
// 檢查有沒有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;
}
// 只要一個區域內有非0非1非2非3的標籤, 直接判定為4
else{
ColorBufOrgn_Labeling[Row-1][Col-1] = 4;
ColorBufOrgn_Labeling[Row ][Col-1] = 4;
ColorBufOrgn_Labeling[Row 1][Col-1] = 4;
ColorBufOrgn_Labeling[Row-1][Col ] = 4;
ColorBufOrgn_Labeling[Row ][Col ] = 4;
ColorBufOrgn_Labeling[Row 1][Col ] = 4;
ColorBufOrgn_Labeling[Row-1][Col 1] = 4;
ColorBufOrgn_Labeling[Row ][Col 1] = 4;
ColorBufOrgn_Labeling[Row 1][Col 1] = 4;
}
}
}
}
}
// Labeling後的圖
for(int Row=0;Row
RGBQUAD *Pixel5=(RGBQUAD*)Pic5->ScanLine[Row];
for(int Col=0;Col
switch( ColorBufOrgn_Labeling[Row][Col]){
case 1: // Label value =1, Red
ColorBufOrgn[Row][Col][2]=255;
ColorBufOrgn[Row][Col][1]=0;
ColorBufOrgn[Row][Col][0]=0;
break;
case 2: // Label value =2, Green
ColorBufOrgn[Row][Col][2]=0;
ColorBufOrgn[Row][Col][1]=255;
ColorBufOrgn[Row][Col][0]=0;
break;
case 3: // Label value =3, Blue
ColorBufOrgn[Row][Col][2]=0;
ColorBufOrgn[Row][Col][1]=0;
ColorBufOrgn[Row][Col][0]=255;
break;
case 4: // Label value =4, Yellow
ColorBufOrgn[Row][Col][2]=255;
ColorBufOrgn[Row][Col][1]=255;
ColorBufOrgn[Row][Col][0]=0;
break;
default:
break;

}
Pixel5->rgbBlue= (Byte)ColorBufOrgn[Row][Col][0];
Pixel5->rgbGreen=(Byte)ColorBufOrgn[Row][Col][1];
Pixel5->rgbRed= (Byte)ColorBufOrgn[Row][Col][2];
}
}
Form1->Image7->Invalidate();
}
//------------------------------------------------------------------------------
void Center_Coordinate(void)
{
// 存重心座標Row
float Center_Label_Row_1=0,Center_Label_Row_2=0,Center_Label_Row_3=0,Center_Label_Row_4=0;
// 存重心座標Col
float Center_Label_Col_1=0,Center_Label_Col_2=0,Center_Label_Col_3=0,Center_Label_Col_4=0;
// 各標籤點數
int Nums_Label_1=0,Nums_Label_2=0,Nums_Label_3=0,Nums_Label_4=0;

// 累計各標籤值的點數(面積)、座標值
for(int Row=0;Row for(int Col=0;Col switch(ColorBufOrgn_Labeling[Row][Col]){
case 1: // 標籤值為1
Center_Label_Row_1 = Center_Label_Row_1 Row;
Center_Label_Col_1 = Center_Label_Col_1 Col;
Nums_Label_1 ;
break;
case 2: // 標籤值為2
Center_Label_Row_2 = Center_Label_Row_2 Row;
Center_Label_Col_2 = Center_Label_Col_2 Col;
Nums_Label_2 ;
break;
case 3: // 標籤值為3
Center_Label_Row_3 = Center_Label_Row_3 Row;
Center_Label_Col_3 = Center_Label_Col_3 Col;
Nums_Label_3 ;
break;
case 4: // 標籤值為4
Center_Label_Row_4 = Center_Label_Row_4 Row;
Center_Label_Col_4 = Center_Label_Col_4 Col;
Nums_Label_4 ;
break;
default:
break;
}
}
}

// 設定四個Label的面積都要大於拉霸門檻,才進行下一步的處理
Form1->Label22->Caption = Form1->TrackBar3->Position;
// 面積判定的if
if ( (Nums_Label_1 > Form1->TrackBar3->Position)
&& (Nums_Label_2 > Form1->TrackBar3->Position)
&& (Nums_Label_3 > Form1->TrackBar3->Position)
&& (Nums_Label_4 > Form1->TrackBar3->Position)){
// 依標籤值分別計算區域重心
//Label=1 Center
Center_Label_Row_1 = Center_Label_Row_1 / Nums_Label_1;
Center_Label_Col_1 = Center_Label_Col_1 / Nums_Label_1;
//Label=2 Center
Center_Label_Row_2 = Center_Label_Row_2 / Nums_Label_2;輸入程式碼




[/code]

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