* 该例程展示了如何在高纹理图像中检测mura缺陷
*
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')
* 3通道图像分解
decompose3 (Image, R, G, B)
* 缺陷的特征是暗斑。因此,通过从原始图像中减去估计的背景光照,使缺陷突出。
* 估计图像背景光照
estimate_background_illumination (B, ImageFFT1)
sub_image (B, ImageFFT1, ImageSub, 2, 100)
* Median filter smoothes out the fine texture, simplifying the following
* segmentation and final detection of defects.
median_image (ImageSub, ImageMedian, 'circle', 9, 'mirrored')
* 基于分水岭算法的阈值分割
watersheds_threshold (ImageMedian, Basins, 20)
* 暗斑对应于较低的能量
cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
* 能量值<0.05的为暗斑,置true,反之false,选取暗斑区域
Mask := Energy [<=] 0.05
select_mask_obj (Basins, Defects, Mask)
*
dev_display (Image)
dev_display (Defects)
count_obj (Defects, NDefects)
disp_message (WindowHandle, NDefects + ' \'mura\' defects detected', 'window', 12, 12, 'red', 'true')
if (F < 2)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
**** 函数 estimate_background_illumination (B, ImageFFT1)
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(Image : ImageFFT : Direction, Norm, ResultType, Width : )计算图像的实数值快速傅里叶变换
gen_gauss_filter( : ImageGauss : Sigma1, Sigma2, Phi, Norm, Mode, Width, Height : )生成频率域的高斯滤波器
convol_fft(ImageFFT, ImageFilter : ImageConvol : : )在频率域将图像与滤波器进行卷积
例:
gen_highpass(Highpass,0.2,'n','dc_edge',Width,Height)
fft_generic(Image,ImageFFT,'to_freq',-1,'none','dc_edge','complex')
convol_fft(ImageFFT,Highpass,ImageConvol)
fft_generic(ImageConvol,ImageResult,'from_freq',1,'none','dc_edge','byte')
cooc_feature_image(Regions, Image : : LdGray, Direction : Energy, Correlation, Homogeneity, Contrast)计算区域图像的共生矩阵并计算其灰度特征值
该部分代码很巧妙,很好的替代for循环
cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
Mask := Energy [<=] 0.05
select_mask_obj (Basins, Defects, Mask)