halcon find scatches bandpass fft

* This program shows how to detect defects (scratches) in
* an inhomogeneously illuminated surface by filtering in
* the frequency domain.
* First, a suitable bandpass filter is created. Then, the
* input image is fourier transformed and filtered in the
* frequency domain, so that high frequency information is
* enhanced. Finally, it is transformed back to the
* spatial domain and the enhanced defects are post-processed
* by morphology.
* 
*首先创建带通滤波器,然后输入福利变换的频域图,增强高频信息
*组以后将其转换回空间域和增强缺陷后形态学处理
*
*

dev_update_off ()
dev_close_window ()
read_image (Image, 'surface_scratch')
invert_image (Image, ImageInverted)
*取反图像 g' = 255 - g
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)
*通过一个循环结构元素来Dilate一个区域
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')
*创建一个来自XLD轮廓的区域
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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值