ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Halcon的texture_laws算子自我研究

2021-07-10 20:02:19  阅读:270  来源: 互联网

标签:滤波器 卷积 Shift texture Halcon filter SSE laws


本篇博文来自博主Imageshop,打赏或想要查阅更多内容可以移步至Imageshop。

 

转载自:https://www.cnblogs.com/Imageshop/p/13490534.html   侵删

  Halcon里有个texture_laws 算子,最近实现了下,记录下相关细节。

       Halcon的文档里对该算子是这样描述的:

       texture_laws — Filter an image using a Laws texture filter.

  Signature

    texture_laws(Image : ImageTexture : FilterTypes, Shift, FilterSize : )

  Description

    texture_laws applies a texture transformation (according to Laws) to an image. This is done by convolving the input image with a special filter mask. The filters are:

    9 different 3×3 matrices obtainable from the following three vectors:

      l = [ 1 2 1 ],
      e = [ -1 0 1 ],
      s = [ -1 2 -1 ]
    25 different 5×5 matrices obtainable from the following five vectors:
      l = [ 1 4 6 4 1 ],
      e = [ -1 -2 0 2 1 ],
      s = [ -1 0 2 0 -1 ],
      w = [ -1 2 0 -2 1 ]
      r = [ 1 -4 6 -4 1 ],
    49 different 7×7 matrices obtainable from the following seven vectors:
      l = [ 1 6 15 20 15 6 1 ],
      e = [ -1 -4 -5 0 5 4 1 ],
      s = [ -1 -2 1 4 1 -2 -1 ],
      w = [ -1 0 3 0 -3 0 1 ],
      r = [ 1 -2 -1 4 -1 -2 1 ],
      u = [ 1 -4 5 0 -5 4 -1 ]
      o = [ -1 6 -15 20 -15 6 -1 ]
  The names of the filters are mnemonics for “level,” “edge,” “spot,” “wave,” “ripple,” “undulation,” and “oscillation.”
  For most of the filters the resulting gray values must be modified by a Shift. This makes the different textures in the output image more comparable to each other, provided suitable filters are used.The name of the filter is composed of the letters of the two   vectors used, where the first letter denotes convolution in the column direction while the second letter denotes convolution in the row direction.


  FilterTypes (input_control) string → (string)
    Desired filter.
    Default value: 'el'
    Suggested values: 'll', 'le', 'ls', 'lw', 'lr', 'lu', 'lo', 'el', 'ee', 'es', 'ew', 'er', 'eu', 'eo', 'sl', 'se', 'ss', 'sw', 'sr', 'su', 'so', 'wl', 'we', 'ws', 'ww', 'wr', 'wu', 'wo', 'rl', 're', 'rs', 'rw', 'rr', 'ru', 'ro', 'ul', 'ue', 'us', 'uw', 'ur', 'uu', 'uo', 'ol', 'oe', 'os', 'ow', 'or', 'ou', 'oo'
  Shift (input_control) integer → (integer)
    Shift to reduce the gray value dynamics.
    Default value: 2
    List of values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  FilterSize (input_control) integer → (integer)
    Size of the filter kernel.
    Default value: 5
    List of values: 3, 5, 7

  这个算子通常用来进行纹理分析,其实现过程其实很简单。第一,滤波器的大小只有3、5、7三种,第二、滤波器的类型根据滤波器大小决定由多少种。

  以滤波器尺寸为3,滤波器类型为‘el‘,Shift = 2为例来说明计算过程。

    对应的e = [ -1 0 1 ], l = [ 1 2 1 ]。

       其实就是对原图进行e‘*l的一个卷积。

         -1   -2   -1
         0    0    0
         1    2   1

  卷积矩阵如上所示,那么假如卷积的结果为s,则最终的结果为s >> shift, shift起到了调整图像最后亮度的作用。

  如果滤波器的尺寸为5或者7,那么对应的卷积矩阵就是5*5或者7*7的,这各时候直接卷积速度比比较慢,其实,在本算法中,是没有必要这样的,很明显,这是个行列可分离的卷积。

  也就是说,可以先进行方向的卷积,得到中间结果,然后在对中间结果进行列方向的卷积。这样滤波器尺寸为5和7的分别指需要做5+5和7+7次计算,效率打了很多。

        具体实现上,从速度角度考虑,这个中间结果可以用signed short类型来保存,在观察这些卷积的系数,都在signed char范围内,因此,在从原图到中间结果的过程中,可以用一个非常高效的SSE函数来实现,即_mm_maddubs_epi16.

   这个函数的功能如下:

       他可以一次性实现16次乘法和加法,地方分别是字节数和有符号的字节数,非常有效。

       在中间结果到最终值时,又可以利用_mm_madd_epi16这个针对16位数的SSE函数,他同样能一次性实现多个乘法和加法。

      

       

   就是这样一个简单的优化,我测试了一下速度,测试对象为3000*2000的RGB数据, 分别使用3、5、7的滤波器尺寸,时间比例如下:

        

  Halcon不同尺寸的耗时基本相同,我这里明显尺寸越小,耗时越短,并且速度比halcon要稍微快那么一点点。

   测试算法在我的SSE Demo的ImageInfo 菜单下Laws Texture下。

        本文Demo下载地址:  http://files.cnblogs.com/files/Imageshop/SSE_Optimization_Demo.rar,里面的所有算法都是基于SSE实现的。

标签:滤波器,卷积,Shift,texture,Halcon,filter,SSE,laws
来源: https://blog.csdn.net/weixin_39450742/article/details/118600604

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有