当前位置:   article > 正文

Halcon表面缺陷检测-不均匀光照的表面缺陷_halcon处理图片光照不均匀

halcon处理图片光照不均匀

对应示例程序:
find_scratches_bandpass_fft.hdev

目标:实现不均匀光照的表面缺陷。

思路为:
      先创建一个合适的带通滤波器,然后把图像(例程做了图像反转)傅里叶变换在频域滤波,加强高频部分,然后变回时域做形态学处理,最后通过line_gauss检测出缺陷。

图像:
在这里插入图片描述

代码:

dev_update_off ()
dev_close_window ()
read_image (Image, 'surface_scratch')
invert_image (Image, ImageInverted) //反转图像
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
* 
* Optimize the speed of the fast fourier transform
* Message := 'Optimize the speed of the fast fourier transform.'
* Message[1] := 'Please wait...'
* disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* optimize_rft_speed (Width, Height, 'standard')
* disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
* 
* Enhance the scratches by filtering in the frequency domain
gen_sin_bandpass (ImageBandpass, 0.4, 'none', 'rft', Width, Height) //生成带通滤波器
rft_generic (ImageInverted, ImageFFT, 'to_freq', 'none', 'complex', Width) //空间域到频率域
convol_fft (ImageFFT, ImageBandpass, ImageConvol)  //计算卷积
rft_generic (ImageConvol, Lines, 'from_freq', 'n', 'byte', Width)  //频率域到空间域
* 
* Segment the scratches by using morphology
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, LinesXLD, 0.8, 3, 5, 'dark', 'false', 'bar-shaped', 'false')  //检测线
union_collinear_contours_xld (LinesXLD, UnionContours, 40, 3, 3, 0.2, 'attr_keep') //连接近似共线轮廓
select_shape_xld (UnionContours, SelectedXLD, 'contlength', 'and', 15, 1000)
gen_region_contour_xld (SelectedXLD, RegionXLD, 'filled')
union1 (RegionXLD, RegionUnion)
dilation_circle (RegionUnion, RegionScratches, 10.5)
* 
* Display the results 显示结果
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_colored (12)
dev_display (Image)
dev_display (RegionScratches)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

用到的几个算子:
      gen_sin_bandpass—生成带通滤波器
      rft_generic–傅里叶变换
      convol_fft–卷积
      rft_generic–傅里叶变换

      lines_gauss–检测线
      union_collinear_contours_xld–联合近似共线轮廓

参考资料:
[1]: https://blog.csdn.net/u013404374/article/details/46982229

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/86656
推荐阅读
相关标签
  

闽ICP备14008679号