Hello Mat

 找回密码
 立即注册
查看: 9634|回复: 0

Mura_defect缺陷检测-分水岭分割watersheds_threshold

[复制链接]

1323

主题

1551

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22647
发表于 2017-1-7 22:41:58 | 显示全部楼层 |阅读模式
* 关闭窗口
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 函数如下:
  1. get_image_size (Image, Width, Height)
  2. rft_generic(Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
  3. gen_gauss_filter (ImageGauss, 50, 50, 0, 'n', 'rft', Width, Height)
  4. convol_fft (ImageFFT, ImageGauss, ImageConvol)
  5. rft_generic (ImageConvol, IlluminationImage, 'from_freq', 'none', 'byte', Width)
  6. return ()
复制代码
这是rft_generic,也就是时域傅里叶变换。区别于fft_generic





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-11-22 18:36 , Processed in 0.178620 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表