Halcon开始一个视觉项目--图像预处理(2.1)
Halcon开始一个视觉项目之图像预处理
前言
介绍常用的一些预处理算子。
图像预处理的预处理往往是将图片转为灰度图片(当然不会是全部),这主要是为了简化图像处理的复杂性并降低计算成本。
将三维的彩色图像转换为一维的灰度图像,减少了颜色分量,同时也减少了数据量,降低了存储空间的需求,同时保持(一般图像处理任务中最需要的)图像的基本结构和纹理信息。此外,灰度图像对噪声的鲁棒性更强,并且由于减少了图像的维度,可以显著提高图像处理算法的运算速度。
灰度化
rgb1_to_gray (Image, GrayImage)

滤波
均值滤波:平滑图像,过滤噪声。
mean_image (Image, ImageMean, MaskWidth , MaskHeight)
read_image(Image,'ImageName')
mean_image(Image,Mean,3,3)
dev_display(Mean)

中值滤波:对椒盐噪声特别有效。
median_image(Image, ImageMedian, MaskType, Radius, Margin)
read_image (Image, 'ImageName')
median_image (Image, Median, 'circle', 3, 'continued')
dev_display(Median)

高斯滤波:基于高斯函数进行滤波,平滑图像。
gauss_filter(Image, ImageGauss, Size)
read_image (Image, 'ImageName')
gauss_filter(Input,Gauss,7)
regiongrowing(Gauss,Segments,7,7,5,100)

导向滤波:在保持边缘的同时去除噪声。
guided_filter(Image, ImageGuide, ImageGuided, Radius, Amplitude)
read_image (Image, 'ImageName')
* Edge-preserving smoothing
guided_filter (Image, Image, ImageGuided, 5, 20)
* Rolling filter (5 iterations)
gen_image_proto (Image, ImageGuide, 0)
for I := 1 to 5 by 1
guided_filter (Image, ImageGuide, ImageGuide, 5, 20)
endfor

阈值处理及分割
阈值处理
基于固定阈值将图像二值化。
threshold(Image, Region, MinGray, MaxGray)
获取灰度值处于[MinGray, MaxGray]的区域,其中MinGray, MaxGray手动定义,可通过Halcon HDevelop工具栏中“灰度直方图”工具获取。
threshold(Image,Region,50,255)
动态阈值分割,根据局部特性确定阈值。
dyn_threshold(OrigImage, ThresholdImage, RegionDynThresh, Offset, LightDark)
mean_image(Image,Mean,D*2+1,D*2+1)
dyn_threshold(Image,Mean,Seg,5,'light')
connection(Seg,Regions)
自动阈值分割,根据相关算法对图像进行自动阈值分割。
binary_threshold(Image, Region, Method, LightDark, UsedThreshold)
binary_threshold (ImageReduced, Region, 'max_separability', 'dark', UsedThreshold)
其中Method可选:‘max_separability’, ‘smooth_histo’,LightDark可选:‘dark’, ‘light’。
分割
reduce_domain(Image, Region, ImageReduced)
这里的Region可继承阈值处理中得到的输出,即阈值处理与分割往往是连续的两步操作:阈值分割。
(阈值处理是提取出区域,分割是将区域从图像分割出来,形成新的图像)
形态学操作
在阈值处理的时候,我们发现得到Region可能并不全,或者过多,又可能存在需要的区域却并不在Region上,则在分割之前,可以进行形态学处理。
待续。
