Simple application of Halcon's image segmentation operator binary_threshold
Take an image segmentation example to briefly introduce the application of the operator binary_threshold:
Segment the nine black points in the image below from the image and extract the area and center coordinates of the nine points in order
Image processing process:
//读取图像
read_image (Image, 'C:/Users/SUNSONG/Desktop/Image_1.bmp')
//二值化阈值分割
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
//计算连通区域数量
connection (Region, ConnectedRegions)
//根据特征选择区域(这里根据面积进行选择)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 6031.75, 32110.1)
//填充区域
fill_up (SelectedRegions, RegionFillUp)
//腐蚀区域边界
erosion_circle (RegionFillUp, RegionErosion, 1.5)
//对区域进行排序
sort_region (RegionErosion, SortedRegions, 'character', 'true', 'row')
//计算每个区域的面积 中心坐标
area_center (SortedRegions, Area, Row, Column)
Image processing results:
Introduction to the use of related operators:
(1)binary_threshold
binary_threshold(Image : Region : Method, LightDark : UsedThreshold)
Image : the image to be divided
Region : The divided region
Method : Segmentation method. Two methods are provided:'max_separability' and'smooth_histo'. These two methods can only be used for images with bimodal histograms
LightDark : Extract dark background or light background
UsedThreshold : Used Threshold
(2)select_shape
Open the feature histogram, perform feature selection, then adjust the range of the histogram to determine the minimized and maximized values, click to insert the code to generate the operator select_shape
(3)sort_region
sort_region(Regions : SortedRegions : SortMode, Order, RowOrCol : )
Regions : the region to be sorted
SortedRegions : sorted regions
SortMode : the type of sorting
Order : Ascending or descending order
RowOrCol : sort by row or column first
(4)erosion_circle
Use circular elements to corrode the area