目录
1、图像边缘提取原理
2、边缘提取算子介绍
3、图像的亚像素边缘提取
4、亚像素轮廓的特征分析
5、xld的分割及直线拟合
6、圆及椭圆的拟合
7、中心线的提取
1、图像边缘提取原理
2、边缘提取算子使用介绍
read_image (Image1, '1.bmp')rgb1_to_gray (Image1, GrayImage)
*roberts边缘,边缘定位精准roberts (GrayImage, ImageRoberts, 'gradient_sum')
*prewitt_amp边缘,对噪声可以适当抑制。变换后图像有偏移prewitt_amp (GrayImage, ImageEdgeAmp)
*sobel_amp边缘,可以降低边缘模糊程度sobel_amp (GrayImage, EdgeAmplitude, 'sum_abs', 3)
*图像的边缘,参数7:低阈值,参数8:高阈值。一般高阈值是低阈值的1.5倍-2倍edges_image (EdgeAmplitude, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)
3、图像的亚像素边缘提取
read_image (Image1, '1.bmp')rgb1_to_gray (Image1, GrayImage)
*缩小ROI,阈值分割fast_threshold (GrayImage, Region, 150, 255, 20)*连通域connection (Region, ConnectedRegions)*区域排序sort_region (ConnectedRegions, SortedRegions, 'first_point', 'true', 'row')*选择矩形区域-外接矩形select_shape (SortedRegions, SelectedRegions, ['rect2_len1','rect2_len2'], 'and', [110,50], [160,70])
*再排一次序:按列排序sort_region (SelectedRegions, SortedRegions1, 'first_point', 'true', 'column')*始终选择第三个区域:参数3为要选择的哪一个区域select_obj (SortedRegions1, ObjectSelected, 3)
*正常的膨胀需求用dilation_circle,如果想对一个区域进行平滑操作的时候用闭操作closing_circledilation_circle (ObjectSelected, RegionDilation, 5)*将选出来处理好的区域从原灰度图片上裁剪出来reduce_domain (GrayImage, RegionDilation, ImageReduced)
*边缘检测-cannyedges_sub_pix (ImageReduced, Edges, 'canny', 1, 10, 20)
4、亚像素轮廓的特征分析
*XLD筛选,参数3,周长select_shape_xld (Edges, SelectedXLD, 'contlength', 'and', 80, 99999)
5、xld的分割及直线拟合
*轮廓XLD的分割,参数3:分割方式,参数4:圆滑程度,参数5和参数6:最小和最大线的距离segment_contours_xld (UnionContours, ContoursSplit, 'lines_circles', 5, 4, 2)
*选择矩形下部没连接到一起的水平线,根据线的角度来选择select_shape_xld (SelectedXLD, SelectedXLD1, 'phi', 'and', -0.1, 0.1)
*对选出来的直线拟合,参数2,'tukey'是最小2乘拟合、'huber'是考虑权重拟合fit_line_contour_xld (SelectedXLD1, 'huber', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
*拟合后的线不够长,将起始的列往左移动(减去5个像素点)gen_contour_polygon_xld (Contour, [RowBegin,RowEnd], [ColBegin-5,ColEnd])
*将其他的线也选择出来select_shape_xld (SelectedXLD, SelectedXLD2, 'phi', 'and', 0.2, 3.14)*将两次选出来的线放到一个集合中concat_obj (SelectedXLD2, Contour, ObjectsConcat)*将集合中的两个线,合并连接到一起union_adjacent_contours_xld (ObjectsConcat, UnionContours1, 10, 1, 'attr_keep')
*将线围起来的区域转换成轮廓gen_region_contour_xld (UnionContours1, Region1, 'filled')
*使用腐蚀,将多出来的去掉opening_circle (Region1, RegionOpening, 3.5)*再求边缘boundary (RegionOpening, RegionBorder, 'inner')
*求出来的边缘并不是太好,使用膨胀操作dilation_circle (RegionBorder, RegionDilation1, 3.5)*膨胀后再从原图中进行裁剪reduce_domain (GrayImage, RegionDilation1, ImageReduced1)
*再用刚才的边缘,所求得的边缘就要好多了 edges_sub_pix (ImageReduced1, Edges1, 'canny', 1, 20, 40)
*再进行连接union_adjacent_contours_xld (Edges1, UnionContours2, 10, 1, 'attr_keep')
6、圆及椭圆的拟合
dev_close_window ()dev_open_window (0, 0, 512, 512, 'black', WindowHandle)read_image (Image1, '1.bmp')
*画圆draw_circle (WindowHandle, Row, Column, Radius)*生成圆gen_circle (Circle, Row, Column, Radius)*裁剪reduce_domain (Image1, Circle, ImageReduced)
*提取边缘edges_sub_pix (ImageReduced, Edges, 'canny', 1, 10, 20)*选择轮廓形状select_shape_xld (Edges, SelectedXLD, 'contlength', 'and', 80, 99999)
*对选出来的轮廓进行分割,然后求出分割最长的那条线segment_contours_xld (SelectedXLD, ContoursSplit, 'lines_circles', 5, 4, 2)*分割的xld长度,长度值保存在Length数组中length_xld (ContoursSplit, Length)*求数组最大值tuple_max (Length, Max)*选出分割最长的线select_shape_xld (ContoursSplit, SelectedXLD1, 'contlength', 'and', Max-1, 99999)
*对选出来的线,用圆的拟合。参数2:选择拟合方法,回归的形式fit_circle_contour_xld (SelectedXLD1, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius1, StartPhi, EndPhi, PointOrder)*生成圆轮廓-拟合好的分割线gen_circle_contour_xld (ContCircle, Row1, Column1, Radius1, 0, 6.28, 'positive', 1)
*椭圆拟合*fit_ellipse_contour_xld (SelectedXLD1, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row2, Column2, Phi, Radius11, Radius2, StartPhi1, EndPhi1, PointOrder1)*生成椭圆轮廓-拟合好的分割线*gen_ellipse_contour_xld (ContEllipse, Row2, Column2, Phi, Radius11, Radius2, StartPhi1, StartPhi1, 'positive', 1.5)
7、中心线的提取
介绍::中心线是出于某区域中心的线,比如图中的道路中心,很多情况下需要求解中心。
求解方法:
read_image (Image1, '1.bmp')rgb1_to_gray (Image1, GrayImage)
*中心线提取,亮的区域。*参数3:提取的中心线光滑程度,通常取1.2-1.5。参数4参数5:边缘高低阈值,类似于canny。参数6:中心线是dark还是lightlines_gauss (GrayImage, Lines, 1.5, 3, 8, 'light', 'true', 'bar-shaped', 'true')
*提取黑色的中心线lines_gauss (GrayImage, Lines1, 1.5, 3, 8, 'dark', 'true', 'bar-shaped', 'true')
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


