1.1应用示例思路
(1) 利用Blob分析(一般步骤:图像阈值分割、获取连通区域、计算Blob的相关几何特征),获取ROI区域。
(2) 剪切出来ROI区域中的图像,并对图像进行边缘提取。
(3) 拟合矩形轮廓,并生成矩形XLD轮廓,来完成对PCB图像上Pads区域的定位。
1.2应用实例代码
*读取图像
read_image (Image, 'die_pads')
*关闭已经打开的图形窗口
dev_close_window ()
*获取图像的宽高
get_image_size (Image, Width, Height)
*打开一个新的图形窗口
dev_open_window (0, 0, Width * 2, Height * 2, 'black', WindowHandle)
*设置图像在图形窗口中显示的范围
dev_set_part (0, 0, Height - 1, Width - 1)
* Find the pads in the image using blob analysis.
*使用全局阈值对图像进行快速阈值分割
fast_threshold (Image, Region, 180, 255, 20)
*计算区域的连通组件
connection (Region, ConnectedRegions)
*根据面积('area')和区域的长轴和短轴的比值('anisometry')的特征筛选区域
select_shape (ConnectedRegions, SelectedRegions, ['area', 'anisometry'], 'and', [200, 1], [1200, 2])
* Construct a ROI for subpixel-accurate edge detection.
*填充区域的孔洞
fill_up (SelectedRegions, RegionFillUp)
*将区域转化为凸形
shape_trans (RegionFillUp, RegionTrans, 'convex')
*获取凸形区域的边界
boundary (RegionTrans, RegionBorder, 'inner')
*对边界区域进行膨胀操作
dilation_circle (RegionBorder, RegionDilation, 2.5)
*将所有输入区域合并为一个区域
union1 (RegionDilation, RegionUnion)
* Perform the subpixel-accurate edge detection.
*剪切出来ROI区域中的图像
reduce_domain (Image, RegionUnion, ImageReduced)
*对图像进行边缘提取
edges_sub_pix (ImageReduced, Edges, 'sobel_fast', 0.5, 20, 40)
* Select the edge fragments that belong to the pads.
select_shape_xld (Edges, SelectedContours, 'contlength', 'and', 10, 200)
* Merge adjacent edge fragments to obtain one contour per pad.
*将相邻的轮廓合并为一个轮廓
union_adjacent_contours_xld (SelectedContours, UnionContours, 2, 1, 'attr_keep')
* Fit rectangles robustly to the pads' edges.
*将UnionContours轮廓拟合成为一个仿射矩形轮廓
fit_rectangle2_contour_xld (UnionContours, 'tukey', -1, 0, 0, 3, 2, Row, Column, Phi, Length1, Length2, PointOrder)
* Generate rectangles from the fitting result for visualization purposes.
*创建具有任意方向的矩形XLD轮廓
gen_rectangle2_contour_xld (Rectangle, Row, Column, Phi, Length1, Length2)
*显示图像
dev_display (Image)
*设置显示对象的颜色数目
dev_set_colored (12)
*显示pads区域
dev_display (Rectangle)