工业上很多产品都存在大大小小的网格,花纹等,这些产品的一些缺陷瑕疵,会因为产品自带的网格、花纹所干扰,导致增大缺陷检测的难度,下面是一个背景网格产品刮伤检测的实例:
产品原图:
dev_update_off ()
dev_close_window ()
Path := 'lcd/'
read_image (Image, Path + 'mura_defects_blur_01')
get_image_size (Image, Width, Height)
dev_open_window_fit_size (0, 0, Width, Height, 640, 480, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('red')
ScaleFactor := 0.4
calculate_lines_gauss_parameters (17, [25,3], Sigma, Low, High)
for f := 1 to 3 by 1
read_image (Image, Path + 'mura_defects_blur_' +f$'.2i')
decompose3 (Image, R, G, B)
rft_generic (B, ImageFFT, 'to_freq', 'none', 'complex', Width)
gen_gauss_filter (ImageGauss, 100, 100, 0, 'n', 'rft', Width, Height)
convol_fft (ImageFFT, ImageGauss, ImageConvol)
rft_generic (ImageConvol, ImageFFT1, 'from_freq', 'none', 'byte', Width)
sub_image (B, ImageFFT1, ImageSub, 2, 100)
zoom_image_factor (ImageSub, ImageZoomed, ScaleFactor, ScaleFactor, 'constant')
get_domain (ImageZoomed, Domain)
erosion_rectangle1 (Domain, RegionErosion, 7, 7)
reduce_domain (ImageZoomed, RegionErosion, ImageReduced)
lines_gauss (ImageReduced, Lines, Sigma, Low, High, 'dark', 'true', 'gaussian', 'true')
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_scale_local (HomMat2DIdentity, 1 / ScaleFactor, 1 / ScaleFactor, HomMat2DScale)
affine_trans_contour_xld (Lines, Defects, HomMat2DScale)
dev_display (Image)
dev_display (Defects)
stop ()
endfor
展现结果: