- this example shows how to detect mura defects
- in blurred images
dev_close_window ()
dev_update_off ()
Path := ‘C:/Users/shang/Desktop/新建文件夹2/Image_’
read_image (Image, Path + ‘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 + f$’.2i’)
*decompose3 (Image, R, G, B)
* correct side illumination
*傅里叶变换
rft_generic (Image, 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 (Image, ImageFFT1, ImageSub, 2, 100)
*将图像ImageSub进行放大观察,ImageZoomed为放大后的图像,ScaleFactor, ScaleFactor为长宽放大加数,
*constant为插值方法。
zoom_image_factor (ImageSub, ImageZoomed, ScaleFactor, ScaleFactor, ‘constant’)
* 获取一幅图的区域,目的为避免边框对lines_gauss的影响。
get_domain (ImageZoomed, Domain)
*腐蚀,
erosion_rectangle1 (Domain, RegionErosion, 7, 7)
*在图像ImageZoomed截取RegionErosion大小图片,存放到变量ImageReduced
reduce_domain (ImageZoomed, RegionErosion, ImageReduced)
*检测图像的线条与宽度。ImageReduced, Lines为输入图像与输出的亚像素线条,
*Sigma为高斯平滑系数, Low为后滞阈值分隔低值, High为前置阈值分割高值,
*'dark’表示 提取图像 中的暗线条, 'true’表示 是否提取线条 宽度, 'gaussian’提取线条的模式,
*gaussian在线条不锐利时使用, 'true’表示添加 能够 提取的接合点。
lines_gauss (ImageReduced, Lines, Sigma, Low, High, ‘dark’, ‘true’, ‘gaussian’, ‘true’)
*生成齐次转换矩阵
hom_mat2d_identity (HomMat2DIdentity)
*添加缩放的齐次转换矩阵,HomMat2DIdentity为输入矩阵,
*1 / ScaleFactor, 1 / ScaleFactor为缩放因数, HomMat2DScale为输出的矩阵。
hom_mat2d_scale_local (HomMat2DIdentity, 1 / ScaleFactor, 1 / ScaleFactor, HomMat2DScale)
*对亚像素直线Lines进行仿射变换。
affine_trans_contour_xld (Lines, Defects, HomMat2DScale)
*
dev_display (Image)
dev_display (Defects)
if (f < 3)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endif
endfor