問題提出:求下圖中楔形缺口到圓心的最短距離。html
【涉及知識點講解】spa
1、Region特徵算子3d
在圖形窗口中用鼠標單擊選中某個Region,而後點擊菜單欄的「打開特徵檢測」圖標,就能夠看到當前Region的全部特徵了。htm
由特徵檢測頁面可知,Region的特徵不少,如何知道用什麼算子能夠得到這些特徵呢?blog
① 鼠標放在特徵上懸停。ci
② region_featuresget
2、形態學算子(如下面四個爲例)io
dilation_circleList
erosion_circle遍歷
opening_rectangle1
closing_rectangle1
拓展閱讀:http://www.javashuo.com/article/p-ayjsikwe-eb.html
3、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)
http://www.javashuo.com/article/p-rctchlvn-hw.html
4、完整代碼
*方法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')