本例程来做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.