zoukankan      html  css  js  c++  java
  • 图像处理笔记(九):频率域滤波

    这一章我决定简单的了解一下什么是傅里叶变换,傅里叶变换在图像处理中能起到什么样的作用,而不去深究背后原理。

    傅里叶变换

    看了一下这篇专栏:
    https://zhuanlan.zhihu.com/p/19763358
    理解频域和时域。
    算是理论上理解了一下傅里叶变换吧。

    通过傅里叶变换,可以过滤出我们感兴趣的频率上的内容。
    surface的屏幕在运行halcon的时候烫得可以煎鸡蛋。。。触屏的时候把我手指烫了一下。

    下面通过学习Halcon中的例程find_scratches_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)
    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算子使用足够大的半径能够做到把区域圈出来的功能

    Halcon中的几种图像类型

    1. byte
    2. complexe
    3. real
    4. XLD,这个应该不是图像类型

    本次运用到的新的Halcon算子小结

    1. gen_sin_bandpass(ImageFilter, 输出值,生成的滤波器
      Frequency, 频率,0-1
      Norm, 因子归一化方式:‘n'或者'none'
      Mode, 决定了过滤器的"DC terms"在哪里或者过滤器是否可以在实数快速傅里叶变换中使用,针对之后不同的变换,需要做不同的配置。使用rft_generic时,需要配置为'rft'
      Width, 图片的宽
      Height) 图片的高
      生成一个正弦波带通滤波器
    2. rft_generic(Image, 图像
      ImageFFT, 输出值,变换后的图像
      Direction, 正向变换(to_freq)还是反向变换(from_freq)
      Norm, 因子归一化方式:sqrt,n,none,正反向变换时应使用一致的归一化方式
      ResultType, 输出图像的类型
      Width) 需要最优化时间的图像宽度
      对图像做实数快速傅里叶变换
    3. reduce_domain(Image, 图像
      Region, 给定的区域
      ImageReduced) 输出值,缩减定义域后的图像
      减小图像的定义域,新的定义域是给定区域与原图像相交域,因此,新的定义域是原定义域的子集
    4. line_gauss(Image, 图像
      Lines, 输出值,线条,亚像素精度的XLD轮廓
      Sigma, 高斯平滑的程度,0.7-20,越大越平滑
      Low, 阈值,下线
      High, 阈值,上线
      LightDark, 提取亮的还是暗的线条:light,dark
      ExtractWidth, 是否为每个提取宽度:true,false
      LineModel, 设置成非'none'时,会补偿线条不对称的印象,纠正线条位置和宽度:bar-shaped,gaussuan,none,parabolic
      CompleteJunctions) 当不能提取时是否增加接合点:true,false
      检测线条及宽度
      越光滑,阈值的High和Low要越小。

    亚像素: 两个像素之间的更小的东西

  • 相关阅读:
    Windows Store App 主题动画
    Windows Store App 过渡动画
    Windows Store App 控件动画
    Windows Store App 近期访问列表
    Windows Store App 文件选取器
    Windows Store App 访问应用内部文件
    Windows Store App 用户库文件分组
    Windows Store App 获取文件及文件夹列表
    Windows Store App 用户库文件夹操作
    Windows Store App 用户库文件操作
  • 原文地址:https://www.cnblogs.com/yutou2016/p/11114228.html
Copyright © 2011-2022 走看看