Halcon颜色分类-阈值分区法

简介:

             对RGB的单通道图像进行阈值分割。原理是利用每个通道的阈值分割是否能得到相应的区域来判断当前区域的颜色,可用于颜色分类。

 

介绍:

decompose3 (将一个三通道的图像转换为三个图像)
MultiChannelImage (input_object)   Multichannel image. 多通道图像
Image1 (output_object) Output image 1. 通道1,R图像
Image2 (output_object)   Output image 2. 通道2,G图像
Image3 (output_object)   Output image 3. 通道3,B图像
threshold (使用全局阈值分割图像)
Image (input_object)  Input image. 图像
Region (output_object)  Segmented region. 输出的分割区域
MinGray (input_control)  Lower threshold for the gray values.
Default value: 128.0
Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0
灰度值的低阈值
MaxGray (input_control)   Upper threshold for the gray values.
Default value: 255.0
Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0
Restriction: MaxGray >= MinGray
灰度值的高阈值
connection (计算整体区域的单独连通区域)
Region (input_object) Input region. 区域
ConnectedRegions (output_object)   Connected components. 输出的多个单独区域
select_shape (利用形状特征选择区域).
Regions (input_object)  Regions to be examined. 检查的区域
SelectedRegions (output_object)   Regions fulfilling the condition. 输出的满足条件的区域
Features (input_control) Shape features to be checked.
Default value: 'area'
List of values: 'anisometry', 'area', 'area_holes', 'bulkiness', 'circularity', 'column', 'column1', 'column2', 'compactness', 'connect_num', 'contlength', 'convexity', 'dist_deviation', 'dist_mean', 'euler_number', 'height', 'holes_num', 'inner_height', 'inner_radius', 'inner_width', 'max_diameter', 'moments_i1', 'moments_i2', 'moments_i3', 'moments_i4', 'moments_ia', 'moments_ib', 'moments_m02', 'moments_m02_invar', 'moments_m03', 'moments_m03_invar', 'moments_m11', 'moments_m11_invar', 'moments_m12', 'moments_m12_invar', 'moments_m20', 'moments_m20_invar', 'moments_m21', 'moments_m21_invar', 'moments_m30', 'moments_m30_invar', 'moments_phi1', 'moments_phi2', 'moments_psi1', 'moments_psi2', 'moments_psi3', 'moments_psi4', 'num_sides', 'orientation', 'outer_radius', 'phi', 'ra', 'rb', 'rect2_len1', 'rect2_len2', 'rect2_phi', 'rectangularity', 'roundness', 'row', 'row1', 'row2', 'struct_factor', 'width'
要检查的形状特征
Operation (input_control)   Linkage type of the individual features.
Default value: 'and'
List of values: 'and', 'or'
与和或
Min (input_control)   Lower limits of the features or 'min'.
Default value: 150.0
Typical range of values: 0.0 ≤ Min ≤ 99999.0
Minimum increment: 0.001
Recommended increment: 1.0
特征值的下限
Max (input_control)   Upper limits of the features or 'max'.
Default value: 99999.0
Typical range of values: 0.0 ≤ Max ≤ 99999.0
Minimum increment: 0.001
Recommended increment: 1.0
Restriction: Max >= Min
特征值的上限

 

使用:

  1. 多通道图像转为单通道图像。
  2. 对单通道图像分别进行阈值分割,形状选择。
read_image (Image, 'E:/照片/RGB.jpg')
decompose3 (Image, Image1, Image2, Image3)

color :=['R', 'G', 'B']
*RGB灰色图像分别对应Image1,Image2,Image3
gen_empty_obj (ImageConcat)
concat_obj (Image1, Image2, ObjectsConcat)
concat_obj (ObjectsConcat, Image3, ImageConcat)

*阈值和面积
min_threshold := [236, 236, 236]
max_threshold := [255, 255, 255]
min_area := [800, 200, 1100]
max_area := [100000, 100000, 100000]

all_color := []
all_row := []
all_col := []

for i := 1 to |color| by 1
    select_obj (ImageConcat, ImageSelected, i)
    *阈值运算
    threshold (ImageSelected, Regions, min_threshold[i - 1], max_threshold[i - 1])
    *多个区域
    connection (Regions, ConnectedRegions)
    *面积选择
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', min_area[i - 1], max_area[i - 1])
    area_center (SelectedRegions, Area, Row, Column)
    count_obj (SelectedRegions, Number) 
    *坐标和对应颜色
    all_row := [all_row, Row]
    all_col := [all_col, Column]
    for j := 1 to Number by 1
        all_color := [all_color, color[i - 1]]
         *disp_message (3600, color[i - 1], 'image', Row[j - 1], Column[j - 1], 'black', 'true')
    endfor
endfor
dev_display (Image)

*显示
for j := 1 to |all_row| by 1
    disp_message (3600, all_color[j - 1], 'image', all_row[j - 1], all_col[j - 1], 'black', 'true')
endfor   
Halcon颜色分类-阈值分区法_第1张图片 RGB.jpg

 

Halcon颜色分类-阈值分区法_第2张图片

你可能感兴趣的:(Halcon,-,集合,Halcon)