halcon例程学习笔记(1)---一维函数的使用

来源:互联网 发布:c语言枚举类型定义 编辑:程序博客网 时间:2024/06/07 20:33

本例程来做halcon10.0版本中的一维函数中auto_threshold.hdev例程

一:例程代码如下:

dev_close_window ()                                                      //关闭窗口
read_image (Aegypt1, 'egypt1')                                     //读取图像
get_image_size (Aegypt1, Width, Height)                  //获取图像宽度和高度
dev_open_window (0, 0, Width, Height, 'black', WindowID)   //打开一个图像大小的窗口
set_display_font (WindowID, 14, 'mono', 'true', 'false')        
dev_set_colored (6)
dev_clear_window ()                      //清空窗口
Sigma := 4                                       //设置平滑初始参数
auto_threshold (Aegypt1, Regions, Sigma)      //图像自动阈值分割

*选定区域的灰度值计算方法

*reduce_domain (Aegypt1, Regions, ImageReduced)
*gray_histo (ImageReduced, Aegypt1, AbsoluteHisto, RelativeHisto)

*

*整个图像区域的灰度值计算
gray_histo (Aegypt1, Aegypt1, AbsoluteHisto, RelativeHisto)        //获取图像的灰度分布值
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_clear_window ()
create_funct_1d_array (AbsoluteHisto, Function)          //创建一维函数数组
smooth_funct_1d_gauss (Function, Sigma, SmoothedFunction)   //使用高斯平滑一维函数
dev_set_color ('red')
funct_1d_to_pairs (SmoothedFunction, XValues, YValues)      //获得对应的一维函数值 并存放到YValues
gen_region_histo (Histo1, YValues, 24, 255, 1)                            //创建区域灰度直方图
dev_display (Aegypt1)
dev_set_color ('white')
gen_region_histo (Histo2, RelativeHisto, 255, 255, 1)        

二:详解关键函数(下面只是自己对函数的个人理解,望指正)

1:gray_histo 计算灰度值分布

gray_histo(Regions,Image : : :AbsoluteHisto,RelativeHisto)

Regions (input_object)  region(-array) object

Region in which the histogram is to be calculated.

Image (input_object)  image object (byte / cyclic / direction / int1 / int2 / uint2 / int4 / real)

Image the gray value distribution of which is to be calculated.

AbsoluteHisto (output_control)  histogram-array (integer)

Absolute frequencies of the gray values.

RelativeHisto (output_control)  histogram-array (real)

Frequencies, normalized to the area of the region.

计算一幅图像中某个选定区域Regions的灰度值分布情况,返回0-255的灰度统计值和相对灰度统计值

2:create_funct_1d_array  创建来自Y数组的一维函数

create_funct_1d_array( : :YValues :Function)

YValues (input_control)  number(-array) (real / integer)

X value for function points.

Function (output_control)  function_1d-array (real / integer)

Created function.

将一个Y(一个离散数据点)创建为一个函数

3:smooth_funct_1d_gauss  将一维函数进行高斯平滑处理  

smooth_funct_1d_gauss( : :Function,Sigma :SmoothedFunction)

Function (input_control)  function_1d-array (real / integer)

Function to be smoothed.

Sigma (input_control)  number (real)

Sigma of the Gaussian function for the smoothing.

Default value:2.0

Suggested values:0.5, 1.0, 2.0, 3.0, 4.0, 5.0

Typical range of values:0.1 ≤ Sigma ≤ 50.0 (lin)

Minimum increment:0.01

Recommended increment:0.2

SmoothedFunction (output_control)  function_1d-array (real / integer)

Smoothed function.

将一个一维函数Function进行高斯平滑拟合为一个函数,并返回被高斯函数平滑后的曲线函数SmoothedFunction

4:funct_1d_to_pairs 计算一维函数的X对应的Y值

funct_1d_to_pairs( : :Function :XValues,YValues)

Function (input_control)  function_1d-array (real / integer)

Input function.

XValues (output_control)  number-array (real / integer)

X values of the function.

YValues (output_control)  number-array (real / integer)

Y values of the function.

计算一个X对应的Y值并存入YValues数组中

5:gen_region_histo 将一个灰度分布转换到一个区域中显示

gen_region_histo( :Region :Histogram,Row,Column,Scale : )

Region (output_object)  region object

Region containing the histogram.

Histogram (input_control)  histogram-array (integer)

Input histogram.

Row (input_control)  point.y (integer)

Row coordinate of the center of the histogram.

Default value:255

Suggested values:100, 200, 255, 300, 400

Typical range of values:0 ≤ Row ≤ 511

Column (input_control)  point.x (integer)

Column coordinate of the center of the histogram.

Default value:255

Suggested values:100, 200, 255, 300, 400

Typical range of values:0 ≤ Column ≤ 511

Scale (input_control)  integer (integer)

Scale factor for the histogram.

Default value:1

List of values:1, 2, 3, 4, 5, 6, 7

Typical range of values:1 ≤ Scale ≤ 10 (lin)

Minimum increment:1

Recommended increment:1

        返回一个区域灰度值图像,在一个区域中。Scale是放大系数,Row,Column是显示的位置