|
* 关闭窗口
dev_close_window ()* 不更新显示
dev_update_off ()
* 读取图像 = 图像+路径
Path := 'lcd/mura_defects_texture_'
read_image (Image, Path + '01')
* 图像大小
get_image_size (Image, Width, Height)
* 关闭了默认的图形窗口,此处就得打开一个图形窗口
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* 设置区域显示为轮廓
dev_set_draw ('margin')
dev_set_line_width (3)
* 轮廓的颜色设置
dev_set_color ('red')
for f := 1 to 2 by 1
read_image (Image, Path + f$'.2i')
decompose3 (Image, R, G, B)
* defects become more apparent
* 高斯高通滤波,去低频,保留纹理边缘信息,凸显缺陷特征
estimate_background_illumination (B, ImageFFT1)
sub_image (B, ImageFFT1, ImageSub, 2, 100)
* halcon中值滤波算子
median_image (ImageSub, ImageMedian, 'circle', 9, 'mirrored')
* halcon分水岭分割
watersheds_threshold (ImageMedian, Basins, 20)
* dark patches corresponding to defects have a very low energy
* halcon求解灰度共生矩阵
cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
* tuple运算,计算能量-0.05小于-1的区域
tuple_find (sgn(Energy - 0.05), -1, Indices)
* 选择Indices所指向的区域
select_obj (Basins, Defects, Indices + 1)
* 显示图像
dev_display (Image)
dev_display (Defects)
count_obj (Defects, NDefects)
disp_message (WindowHandle, NDefects + ' \'mura\' defects detected', 'window', -1, -1, 'red', 'true')
if (f < 2)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
算法要点:
(1)高斯高通滤波--背景估计;(2)分水岭算法--分割;(3)灰度共生矩阵求解特征;
相应地 estimate_background_illumination 函数如下:
- get_image_size (Image, Width, Height)
- rft_generic(Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
- gen_gauss_filter (ImageGauss, 50, 50, 0, 'n', 'rft', Width, Height)
- convol_fft (ImageFFT, ImageGauss, ImageConvol)
- rft_generic (ImageConvol, IlluminationImage, 'from_freq', 'none', 'byte', Width)
- return ()
复制代码 这是rft_generic,也就是时域傅里叶变换。区别于fft_generic
|
|