【HALCON工业机器视觉基础教程】第五章 图像滤波

第五章 图像滤波

5.2 空间域图像滤波

均值滤波

dev_close_window()

dev_open_window(0, 0, 512, 512, 'black', WindowHandle)

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-20.11-Progress/examples/images/circular_barcode.png')

add_noise_white(Image, ImageNoise, 60)

dev_open_window(0, 0, 512, 512, 'black', WindowHandle)

mean_image(ImageNoise, ImageMean, 9, 9)

dev_display(ImageMean)

在这里插入图片描述
均值滤波

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-20.11-Progress/examples/images/particle.png')

threshold(Image, Large, 110, 255)

* 圆角膨胀
dilation_circle(Large, LargeDilation, 7.5)

* 返回补充图像
complement(LargeDilation, NotLarge)

* 返回图像
reduce_domain(Image, NotLarge, ParticlesRed)

* 平滑处理
mean_image(ParticlesRed, ImageMean, 31, 31)

* 动态灰度阈值
dyn_threshold(ParticlesRed, ImageMean, RegionDynThresh, 3, 'light')

* 消除小区域
opening_circle(RegionDynThresh, RegionOpening, 2.5)

*连通域
connection(RegionOpening, ConnectedRegions)

在这里插入图片描述

在这里插入图片描述

频率域高通滤波

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-20.11-Progress/examples/images/tooth_rim.png')

rgb1_to_gray(Image, GrayImage)

get_image_size(GrayImage, Width, Height)

* 构造高斯低通滤波器
gen_gauss_filter(ImageGauss, 0.1, 0.1, 0, 'none', 'dc_center', Width, Height)

* 构造值为1的实数型图像
gen_image_const(Image1, 'real', Width, Height)
paint_region (Image1, Image1, ImageResult, 1, 'fill')

* 构造高斯高通滤波器
sub_image(ImageResult, ImageGauss, ImageSub, 1, 0)

fft_generic(Image,ImageFFT1, 'to_freq', -1, 'none', 'dc_center', 'complex')

* 使用高通滤波器实现滤波
convol_fft(ImageFFT1, ImageSub, ImageConvol)

* 频域转为时域
fft_image_inv(ImageConvol, ImageFFTInv)

频率域带通滤波器

划痕检测

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-20.11-Progress/examples/images/surface_scratch.png')

* 反转图像
invert_image(Image, ImageInvert)

get_image_size(Image, Width, Height)
***********************************************************************
* 图像滤波
* 创建带通滤波器
gen_sin_bandpass(ImageFilter, 0.7, 'none', 'rft', Width, Height)

* 傅里叶变换
rft_generic(ImageInvert, ImageFFT, 'to_freq', 'none', 'complex', Width)

* 带通滤波
convol_fft(ImageFFT, ImageFilter, ImageConvol)

* 反变换
rft_generic(ImageConvol, Lines, 'from_freq', 'n', 'byte', Width)
***********************************************************************
* 得到划痕区域
* 二值化
threshold(Lines, Region, 5, 255)
* 分区域
connection(Region, ConnectedRegions)
* 选择面积
select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 5, 5000)
* 膨胀
dilation_circle(SelectedRegions, RegionDilation, 5.5)
* 合并区域
union1(RegionDilation, RegionUnion)
* 获取图像
reduce_domain(Image,RegionUnion, ImageReduced)
***********************************************************************
* 将划痕区域连成线
* 检测线条及其宽度
lines_gauss(ImageReduced, Lines1, 0.8, 3, 9, 'dark', 'false', 'bar-shaped', 'false')
* 合并近似共线轮廓
union_collinear_contours_xld(Lines1, UnionContours, 40, 3, 3, 0.2, 'attr_keep')
* 按线条长度选择线
select_shape_xld(UnionContours, SelectedXLD, 'contlength', 'and', 15, 1000)

* 从xld等高线创建一个区域
gen_region_contour_xld(SelectedXLD, Region1, 'filled')
union1(Region1, RegionUnion1)
dilation_circle(RegionUnion1, RegionDilation1, 10.5)

在这里插入图片描述
习题
提取纹理

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-20.11-Progress/examples/images/wood_knots.png')

emphasize(Image, ImageEmphasize, 7, 7, 1)

scale_image(Image, ImageScaled, 0.6, 9)

mean_image(Image, ImageMean, 3, 3)

invert_image(ImageMean, ImageInvert)

get_image_size(Image, Width, Height)

gen_sin_bandpass(ImageFilter, 0.2, 'none', 'rft', Width, Height)

rft_generic(ImageInvert, ImageFFT, 'to_freq', 'none', 'complex', Width)

convol_fft(ImageFFT, ImageFilter, ImageConvol)

rft_generic(ImageConvol,Lines,'from_freq', 'n', 'byte', Width)

threshold(Lines, Region, 5,  25)

connection(Region, ConnectedRegions)

select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 10, 5000)

dilation_circle(SelectedRegions, RegionDilation, 5.5)

union1(RegionDilation, RegionUnion)

reduce_domain(ImageMean, RegionUnion, ImageReduced)

lines_gauss(ImageReduced, Lines1, 0.8, 3, 5, 'dark', 'false', 'bar-shaped', 'false')

union_collinear_contours_xld(Lines1, UnionContours, 40, 10, 10, 0.2, 'attr_keep')

select_shape_xld(UnionContours, SelectedXLD, 'contlength', 'and', 100, 1000)

gen_region_contour_xld(SelectedXLD, Region1, 'filled')

union1(Region1, RegionUnion1)

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值