Halcon学习笔记_04:划痕、油污、瑕疵

【转自:J-A:感谢博主分享


划痕、油污、瑕疵,常用的方法有傅里叶变换和Blob分析。
1.表面划痕

invert_image(Image,ImageInvert1) 
mult_image(ImageInvert1, ImageInvert1, ImageResult,0.01, 0) 

gen_sin_bandpass (ImageBandpass, 0.6, 'none', 'rft', Width, Height)
rft_generic (ImageResult, ImageFFT, 'to_freq', 'none', 'complex', Width) 
convol_fft (ImageFFT, ImageBandpass, ImageConvol) 
rft_generic (ImageConvol, Lines, 'from_freq', 'n', 'byte', Width)

texture_laws (Lines, ImageTexture, 'el',3, 5)

为更好的突出前景,一般情况下要求背景颜色较深,可以先用invert_image算子进行灰度值转换。之后的图像相乘,是将对比度进一步扩大。

生成一个正弦形状的带通滤波器,可以去除图像中的噪声。然后傅里叶变换凸显出要检测的划痕。

texture_laws是纹理滤波,适用于布匹表面的划痕,是整个算法的关键所在。
2.亮点、暗点

*找到亮点
mean_image (ImageScaleMax, ImageMean, 9, 9)
dyn_threshold(ImageScaleMax,ImageMean,RegionDynThresh,5,'light' )
connection(RegionDynThresh,ConnectedRegions)

*找到暗点
mean_image(ImageScaleMax,ImageMean,7,7)
dyn_threshold(ImageScaleMax,ImageMean,RegionDynThresh1,5,'dark' )
connection(RegionDynThresh1,ConnectedRegions1)

平滑,动态阈值分割。
3.表面金属伤疤

* 加强图像的对比度
emphasize(Image,ImageEmphasize,Width, Height, 5)
threshold(ImageEmphasize, Region, 0, 5)
fill_up(Region, RegionFillUp2)
connection(RegionFillUp2, ConnectedRegions1)
select_shape(ConnectedRegions1, SelectedRegions2, 'area', 'and', 55000, 60000)
closing_circle(SelectedRegions2, RegionClosing, 13.5)

通过emphasize算子,增强图像对比度,当然前景的突出不仅仅只用这种方法。
4.油污

Sigma1 := 30.0 
Sigma2 := 5.0 
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height) 
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height) 
sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0) 
rgb1_to_gray (Image, GrayImage) 
rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width) 
convol_fft (ImageFFT, Filter, ImageConvol) 
rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width) 
scale_image_range (ImageFiltered, ImageScaled, 0, 255) 

与表面划痕相似,通过两次高斯滤波,结合傅里叶变换。scale_image_range算子的作用:Scale the gray values of an image from the interval [Min,Max] to [0,255]。可以将油污的灰度值凸显出来。

猜你喜欢

转载自blog.csdn.net/y363703390/article/details/81201824