图像中的边被分割成直线和圆,对于作为圆一部分的边,将估计圆参数并显示生成的圆。
*读取图片
read_image (Image, 'double_circle')
*关闭窗口
dev_close_window ()
*获得图片的大小
get_image_size (Image, Width, Height)
*打开窗口
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*分割包含边的区域
*快速二值化
fast_threshold (Image, Region, 0, 120, 7)
*获得区域的边缘---对区域求轮廓
boundary (Region, RegionBorder, 'inner')
*相对于其最小的周围矩形剪裁区域。
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
*膨胀
dilation_circle (RegionClipped, RegionDilation, 2.5)
*抠图
reduce_domain (Image, RegionDilation, ImageReduced)
*在包含边缘的图像子域中,提取亚像素精确边缘。
*使用Deriche、Lanser、Shen或Canny过滤器提取亚像素精确边缘。
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
*将亚像素轮廓等高线分为线段和圆弧或椭圆弧。
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
*进行计数
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
*通过索引号选取数组内的指定元素
select_obj (ContoursSplit, ObjectSelected, I)
*返回xld轮廓的全局属性值
get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
*Attrib有-1 0 1
*将圆拟合到圆的圆弧线段
if (Attrib > 0)
*对XLD轮廓进行圆弧拟合
fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*绘制拟合出来的圆
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
*显示圆
dev_display (ContCircle)
endif
endfor
*设置颜色、线宽
dev_set_colored (12)
dev_set_line_width (3)
*显示边缘
dev_display (ContoursSplit)
*读取图片
read_image (Image, 'double_circle')
*关闭窗口
dev_close_window ()
*获得图片的大小
get_image_size (Image, Width, Height)
*打开窗口
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*分割包含边的区域
*快速二值化
fast_threshold (Image, Region, 0, 120, 7)
*获得区域的边缘---对区域求轮廓
boundary (Region, RegionBorder, 'inner')
*膨胀
dilation_circle (RegionClipped, RegionDilation, 2.5)
*抠图
reduce_domain (Image, RegionDilation, ImageReduced)
*使用Deriche、Lanser、Shen或Canny过滤器提取亚像素精确边缘。
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
*将亚像素轮廓等高线分为线段和圆弧或椭圆弧。
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
*进行计数
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
*通过索引号选取数组内的指定元素
select_obj (ContoursSplit, ObjectSelected, I)
*返回xld轮廓的全局属性值
get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
*Attrib有-1 0 1
*将圆拟合到圆的圆弧线段
if (Attrib > 0)
*对XLD轮廓进行圆弧拟合
fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*绘制拟合出来的圆
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
*显示圆
dev_display (ContCircle)
endif
endfor
*设置颜色、线宽
dev_set_colored (12)
dev_set_line_width (3)
*显示边缘
dev_display (ContoursSplit)
clip_region_rel(Region : RegionClipped : Top, Bottom, Left, Right : )
功能:相对于其最小的周围矩形剪裁区域。
Region :输入区域;RegionClipped :输出区域缩小的区域;Top, Bottom, Left, Right:内缩量。
通过消除接近区域最小周围矩形的部分来减少区域。具体来说,这意味着该区域被剪裁为小
于或等于最小周围矩形的矩形
edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : )
功能: 使用Deriche,Lanser,Shen或Canny过滤器提取亚像素精确边缘
Image :输入图像;Edges :输出的边缘;Alpha:滤波器宽度;
Low:滞后阈值操作的阈值下限;High: 滞后阈值操作的阈值上限
egment_contours_xld(Contours : ContoursSplit :Mode, SmoothCont, MaxLineDist1, MaxLineDist2 : )
功能:分割XLD轮廓为线段和圆弧或椭圆弧
Contours :输入轮廓;ContoursSplit:分割后的轮廓;Mode:轮廓分割模式;
SmoothCont:用于平滑轮廓的点数;MaxLineDist1:轮廓与近似线之间的最大距离(第一次迭代);MaxLineDist2 :轮廓与近似线之间的最大距离(第二次迭代)