缺陷检测之高纹理图像检测

1、代码

* 该例程展示了如何在高纹理图像中检测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 ()

2、结果图像

源图
背景光照图像缺陷增强图像分水岭阈值分割图像缺陷图像

3、算子

  • 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)计算区域图像的共生矩阵并计算其灰度特征值

这里写图片描述

4、小知识点

该部分代码很巧妙,很好的替代for循环

    cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
    Mask := Energy [<=] 0.05
    select_mask_obj (Basins, Defects, Mask)

5、参考

  • Halcon官方例程
  • 3
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值