Region特征算子與形態學運算——第3講
問題提出:求下圖中楔形缺口到圓心的最短距離。
【涉及知識點講解】
一、Region特征算子
在圖形窗口中用鼠標單擊選中某個Region,然後點擊菜單欄的“打開特征檢測”圖標,就可以看到當前Region的所有特征了。
由特征檢測頁面可知,Region的特征很多,如何知道用什麽算子可以獲得這些特征呢?
① 鼠標放在特征上懸停。
② region_features
二、形態學算子(以下面四個為例)
dilation_circle
erosion_circle
opening_rectangle1
closing_rectangle1
拓展閱讀:https://www.cnblogs.com/xh6300/p/6397289.html
三、tuple_concat和tuple_length、tuple_min
tuple叫做元組,類似於C#中的ArrayList。
a := 3
a := [a,4]
tuple_concat (a, 5, Concat)
a := [a,5]
tuple_length (Concat, Length)
len := |a|
tuple_min (a, Min)
minValue := min(a)
https://www.cnblogs.com/xh6300/p/6117688.html
四、完整代碼
*方法1:逐次逼近法
dev_set_draw (‘margin‘)
read_image (Image, ‘circle.jpg‘)
threshold (Image, Region, 0, 80)
opening_circle (Region, Region, 3.5)
smallest_circle (Region, Row, Column, Radius)
*Row, Column即是圓心坐標
gen_circle (Circle, Row, Column, Radius)
gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)
difference (Circle, Region, RegionResult)
*去掉細窄邊緣
opening_circle (RegionResult, RegionResult, 3.5)
*求最小外接圓直徑
diameter_region (RegionResult, Row1, Column1, Row2, Column2, Diameter)
gap := Radius - Diameter
*設置缺省值
realGap := gap
for i := gap to Radius by 1
gen_circle (Circle1, Row, Column, i)
intersection (Circle1, RegionResult, RegionIntersection)
area_center (RegionIntersection, Area, Row3, Column3)
if (Area > 0)
realGap := i
break
endif
endfor
dev_display (Image)
disp_message (3600,‘MinDist1:‘ + realGap, ‘image‘, Row, Column, ‘black‘, ‘true‘)
*方法2:distance_pr
distance_pr (RegionResult, Row, Column, DistanceMin, DistanceMax)
disp_message (3600,‘DistanceMin: ‘ + DistanceMin, ‘image‘, Row, Column, ‘black‘, ‘true‘)
dev_display (Image)
*方法3:遍歷點坐標,求最小距離
get_region_points (RegionResult, Rows, Columns)
Distances := []
for i := 0 to |Rows|-1 by 5
distance_pp (Row, Column, Rows[i], Columns[i], Distance)
Distances := [Distances , Distance]
endfor
tuple_min (Distances, Min)
disp_message (3600,‘MinDist1:‘ + realGap, ‘image‘, Row, Column, ‘black‘, ‘true‘)
disp_message (3600,‘DistanceMin: ‘ + DistanceMin, ‘image‘, Row+20, Column, ‘black‘, ‘true‘)
disp_message (3600,‘Min: ‘ + Min, ‘image‘, Row+40, Column, ‘black‘, ‘true‘)
Region特征算子與形態學運算——第3講