1. 程式人生 > 其它 >30.4、Blob--特徵提取

30.4、Blob--特徵提取

1select_shape(Regions : SelectedRegions : Features, Operation, Min, Max : ) 物件為region    1

2select_shape_xld(XLD : SelectedXLD : Features, Operation, Min, Max : ) 物件為xld    1

3select_shape_std(Regions : SelectedRegions : Shape, Percent : )    物件為region    4

4、特徵檢測工具:    5

5、幾個常用特徵的原理:    6

6fill_up(Region : RegionFillUp : : )    物件為region    8

7fill_up_shape(Region : RegionFillUp : Feature, Min, Max : )    物件為region    8

8connect_and_holes(Regions : : : NumConnected, NumHoles)    物件為region    9

 

特徵描述了區域的"特徵屬性"。區域特徵(形狀特徵)描述區域的的幾何特徵,這些特徵不受"相關的"灰度值影響。灰度值特徵使用了給定影象的灰度值,通常這個影象來自分割出來的區域。特徵提取應用在:

(1)、分割出來區域後,選擇滿足條件的區域

(2)、區域分類,比如OCR

(3)、測量

(4)、質量檢測

特徵提取,建議結合特徵直方圖。筆記《5、影象分割(閾值)》

1、select_shape(Regions : SelectedRegions : Features, Operation, Min, Max : ) 物件為region

    功能:根據形狀特徵選擇區域

    Regions:輸入區域陣列

    SelectedRegions:輸出篩選後的結果

    Features:選擇的特徵,可以選擇多個

    Operation:每個特徵的連結方式(or、and)

    Min, Max:每個特徵的下上限

    

    例子:

    *關閉更新

dev_update_window ('off')

*讀取region

read_region (Region, 'c:/region.reg')

*計算中心

area_center (Region, Area, Row, Column)

dev_display (Region)

for Index := 1 to 2 by 1

select_obj (Region, Region1,Index)

*計算圓度

circularity (Region1, Circularity1)

*計算矩形度

rectangularity (Region1, Rectangularity1)

*顯示資訊

disp_message (3600, '矩形度'+Rectangularity1, 'window', Row[Index-1]-30, Column[Index-1]-20, 'yellow', 'false')

disp_message (3600, '圓形度'+Circularity1, 'window', Row[Index-1]-10, Column[Index-1]-20, 'yellow', 'false')

 

endfor

 

*矩形度中選中了矩形,圓度中篩選了圓。用或or把這兩個關係連結,所以兩個都選中。假如用與and來連結它們關係,兩個都不被選中

select_shape (Region, SelectedRegions, ['circularity','rectangularity'], 'or', [0.80776,0.89606], [0.91279,0.97618])

    注:這個運算元的特徵集合:看附錄《附錄1:region特徵全集(select_shape)》

2、select_shape_xld(XLD : SelectedXLD : Features, Operation, Min, Max : ) 物件為xld

功能:根據形狀特徵選擇輪廓xld contour或多邊形xld polygon

例:

 

draw_xld (ContOut, 3600, 'true', 'true', 'true', 'true')

draw_xld (ContOut1, 3600, 'true', 'true', 'true', 'true')

concat_obj (ContOut, ContOut1, ObjectsConcat)

*選擇面積為7000-8000xld contours

select_shape_xld (ObjectsConcat, SelectedXLD, 'area', 'and', 7000, 8000)

 

*xld contours轉換為xld polygon

gen_polygons_xld (ObjectsConcat, Polygons, 'ramer', 2)

*選擇面積為7000-8000xld polygon

select_shape_xld (Polygons, Selectedpoly, 'area', 'and', 7000, 8000)

注:這個運算元的特徵集合:看附錄《附錄2:xld特徵全集(select_shape_xld)》

3、select_shape_std(Regions : SelectedRegions : Shape, Percent : )    物件為region

    功能:根據指定的形狀選擇區域

    Shape:指定形狀特徵('max_area', 'rectangle1', 'rectangle2'

*建立region區域

gen_circle (ROI_0, 105.5, 41.5, 18.4391)

gen_ellipse (TMP_Region, 96.5, 114.5, rad(40.7321), 47.5079, 8)

union2 (ROI_0, TMP_Region, ROI_0)

gen_rectangle1 (TMP_Region, 85.5, 175.5, 125.5, 255.5)

union2 (ROI_0, TMP_Region, ROI_0)

gen_rectangle2 (TMP_Region, 102.5, 334.5, rad(16.1134), 46.8402, 17.8466)

union2 (ROI_0, TMP_Region, ROI_0)

connection (ROI_0, ConnectedRegions)

*篩選出矩形度在95%以上的

select_shape_std (ConnectedRegions, SelectedRegions, 'rectangle1', 95)

4、特徵檢測工具:

功能:用於特定區域的形狀和灰度值檢測。

例子(檢測region的特徵,自動計算出特徵的大小):

例子2::檢測影象(下圖是用region指定影象的某部分)的相關資訊如最小灰度值,最大灰度值,平均灰度值,各種異性,熵值等。

5、幾個常用特徵的原理:

(1)、最小外接圓

(2)、最小外接齊軸矩形

(3)、最小外接仿射矩形

(4)、凸度:Convexity = 轉換後面積和轉換前面積的比例

(5)、長度

(6)、緊密度

注:這個運算元的特徵集合:看附錄《附錄1:region特徵全集(select_shape)》

6、fill_up(Region : RegionFillUp : : )    物件為region

    功能:填充區域的所有孔洞

7、fill_up_shape(Region : RegionFillUp : Feature, Min, Max : )    物件為region

    功能:根據指定形狀特徵填充區域孔洞

    Feature:輸入特徵,只有'area', 'compactness', 'convexity', 'anisometry', 'phi', 'ra', 'rb', 'inner_circle', 'outer_circle'

    Min, Max:輸入指定特徵的下上限

例子:

*生成region

gen_rectangle1 (ROI_0, 52.5, 116.5, 216.5, 566.5)

gen_circle (TMP_Region, 131.5, 194.5, 63.8122)

difference (ROI_0, TMP_Region, ROI_0)

gen_ellipse (TMP_Region, 135.5, 342.5, rad(-33.2317), 34.6699, 8)

difference (ROI_0, TMP_Region, ROI_0)

gen_circle (TMP_Region, 121.5, 427.5, 22.6274)

difference (ROI_0, TMP_Region, ROI_0)

*填充全部孔洞

fill_up (ROI_0, RegionFillUp)

*填充指定特徵的孔洞---填充面積為1~1111孔洞

fill_up_shape (ROI_0, RegionFillUp1, 'area', 1, 1111)

    

8、connect_and_holes(Regions : : : NumConnected, NumHoles)    物件為region

    功能:計算連通個數和孔洞數量

    *生成區域

gen_rectangle1 (ROI_0, 69.5, 81.5, 172.5, 253.5)

gen_circle (TMP_Region, 112.5, 397.5, 40.8167)

union2 (ROI_0, TMP_Region, ROI_0)

gen_rectangle2 (TMP_Region, 105.5, 532.5, rad(-29.5115), 60.9016, 56.4189)

union2 (ROI_0, TMP_Region, ROI_0)

gen_ellipse (TMP_Region, 121.5, 138.5, rad(-38.2902), 24.2074, 8)

difference (ROI_0, TMP_Region, ROI_0)

gen_ellipse (TMP_Region, 107.5, 378.5, rad(-48.0128), 13.4536, 8)

difference (ROI_0, TMP_Region, ROI_0)

*計算可連通個數已經孔洞個數

connect_and_holes (ROI_0, NumConnected, NumHoles)