The image processing Notes (IX): Frequency domain filtering

In this chapter I decided to simply look at what is the Fourier transform, the Fourier transform in image processing can play what role, rather than to go into the principles behind.

Fourier transform

I looked at this column:
https://zhuanlan.zhihu.com/p/19763358
understand the frequency and time domain.
It is theoretically understand a bit Fourier transform it.

Fourier transform, you can filter out content on the frequency of interest.
surface of the screen when running halcon's too hot to be fried eggs. . . When my fingers touch a bit hot.

By following the learning routine find_scratches_bandpass_fft Halcon, this example is to find a scribe in a plane non-uniform, is achieved by making the filter in the frequency domain.

* 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)
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换行了
* 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(ImageFilter,      输出值,生成的滤波器
*                                Frequency,       频率,0-1
*                                Norm,               因子归一化方式:‘n'或者'none'
*                                Mode,               决定了过滤器的"DC terms"在哪里或者过滤器是否可以在实数快速傅里叶变换中使用,针对之后不同的变换,需要做不同的配置。使用rft_generic时,需要配置为'rft'
*                                Width,               图片的宽
*                                Height)              图片的高
* 之后往往可能跟随着rtf_generic
gen_sin_bandpass (ImageBandpass, 0.4, 'none', 'rft', Width, Height)
* 对图像做实数快速傅里叶变换
* rft_generic(Image,                    图像   
*                   ImageFFT,              输出值,变换后的图像
*                   Direction,                正向变换(to_freq)还是反向变换(from_freq)
*                   Norm,                      因子归一化方式:sqrt,n,none,正反向变换时应使用一致的归一化方式
*                   ResultType,            输出图像的类型
*                   Width)                     需要最优化时间的图像宽度
* 这里对反转后的图像做了一次傅里叶变换
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
* 通过形态学分离出划痕
* 过滤出灰度在5-255的区域
threshold (Lines, Region, 5, 255)
* 连通
connection (Region, ConnectedRegions)
* 选择面积在5-5000的区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5, 5000)
* 使用一个半径为5.5的圆形结构元做膨胀
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')
* 根据形状特征筛选线条轮廓,轮廓总长度在15-1000之间的
select_shape_xld (UnionContours, SelectedXLD, 'contlength', 'and', 15, 1000)
* 通过XLD轮廓创建区域
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)

dilation_circle operator a sufficiently large area of ​​the circle radius can do out function

Several types of images of Halcon

  1. byte
  2. complex
  3. real
  4. XLD, this should not be the type of image

The use of the new operator Halcon Summary

  1. gen_sin_bandpass (ImageFilter, output values generated filter
    Frequency, frequency, 0-1
    Norm, factor in a normalized manner: 'n' or 'none'
    Mode, determines the "DC terms" filter where the filter or whether can be used in real fast Fourier transform, after different for transformation, different configuration needs to be done when using rft_generic, be configured as 'RFT'
    the width, picture width
    high Height) of the picture
    to generate a sine wave bandpass filter device
  2. rft_generic (Image, Image
    ImageFFT, output values of the transformed image
    the Direction, forward transform (to_freq) or inverse transform (from_freq)
    Norm, factor in a normalized manner: sqrt, n, none, should be used to reverse transformation manner consistent normalization
    ResultType, type of output image
    width) needs time to optimize the image width
    of the image to make real fast Fourier transform
  3. reduce_domain (Image, Image
    Region, a given region
    ImageReduced) output values of the reduced image domain
    domain-reduced image, a new domain is a region of the original image given intersection region, therefore, a new domain is a subset of the domain of the original
  4. line_gauss (Image, Image
    Lines, output values, lines, sub-pixel accuracy XLD contour
    Sigma, Gaussian smoothing degree, from 0.7 to 20, the larger the smoother
    Low, the threshold value, offline
    High, the threshold value, on-line
    LightDark, extract bright or dark lines: Light, Dark
    ExtractWidth, whether extracted as the width of each: to true, to false
    LineModel, when set to the non 'none', it compensates for asymmetrical lines impression correct position and width of the line: bar-shaped, gaussuan, none , Parabolic
    CompleteJunctions) whether the increase can not be extracted when the junction: true, false
    detection of the line width and
    the smoother, High and Low thresholds to be smaller.

Sub-pixel: something smaller between two pixels

Guess you like

Origin www.cnblogs.com/yutou2016/p/11114228.html