问题提出:求下图中楔形缺口到圆心的最短距离

 

【涉及知识点讲解】

 

一、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')

 

 

posted on 2019-03-29 22:43  xh6300  阅读(5551)  评论(0编辑  收藏  举报