赞
踩
对应示例程序:
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)
用到的几个算子:
gen_sin_bandpass—生成带通滤波器
rft_generic–傅里叶变换
convol_fft–卷积
rft_generic–傅里叶变换
lines_gauss–检测线
union_collinear_contours_xld–联合近似共线轮廓
参考资料:
[1]: https://blog.csdn.net/u013404374/article/details/46982229
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。