【短道速滑四】Halcon的texture_laws算子自我研究
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实现的。
【短道速滑四】Halcon的texture_laws算子自我研究的更多相关文章
- HALCON中的算子大全(中英对照)
HALCON中的算子大全(中英对照) Chapter 1 :Classification1.1 Gaussian-Mixture-Models1.add_sample_class_gmm功能:把一个训 ...
- 【短道速滑九】仿halcon中gauss_filter小半径高斯模糊优化的实现
通常,我们谈的高斯模糊,都知道其是可以行列分离的算法,现在也有着各种优化算法实现,而且其速度基本是和参数大小无关的.但是,在我们实际的应用中,我们可能会发现,有至少50%以上的场景中,我们并不需要大半 ...
- HALCON学习之算子大全
1.1 Gaussian-Mixture-Models 1.add_sample_class_gmm 功能:把一个训练样本添加到一个高斯混合模型的训练数据上. 2.classify_class_gmm ...
- HALCON初步:算子参数部分三个冒号的意义
HALCON中存在两类基本变量:图像变量(iconic data)和控制变量(control data),其中图像变量包括image, region和XLD contours,控制变量包括intege ...
- Halcon阈值化算子dual_threshold和var_threshold的理解
Halcon中阈值二值化的算子众多,通常用得最多的有threshold.binary_threshold.dyn_threshold等. threshold是最简单的阈值分割算子,理解最为简单:bin ...
- Spark(四)【RDD编程算子】
目录 测试准备 一.Value类型转换算子 map(func) mapPartitions(func) mapPartitions和map的区别 mapPartitionsWithIndex(func ...
- Spark学习之路(四)—— RDD常用算子详解
一.Transformation spark常用的Transformation算子如下表: Transformation算子 Meaning(含义) map(func) 对原RDD中每个元素运用 fu ...
- Spark 系列(四)—— RDD常用算子详解
一.Transformation spark 常用的 Transformation 算子如下表: Transformation 算子 Meaning(含义) map(func) 对原 RDD 中每个元 ...
- spark教程(四)-SparkContext 和 RDD 算子
SparkContext SparkContext 是在 spark 库中定义的一个类,作为 spark 库的入口点: 它表示连接到 spark,在进行 spark 操作之前必须先创建一个 Spark ...
- 【短道速滑一】OpenCV中cvResize函数使用双线性插值缩小图像到长宽大小一半时速度飞快(比最近邻还快)之异象解析和自我实现。
今天,一个朋友想使用我的SSE优化Demo里的双线性插值算法,他已经在项目里使用了OpenCV,因此,我就建议他直接使用OpenCV,朋友的程序非常注意效率和实时性(因为是处理视频),因此希望我能测试 ...
随机推荐
- STL multimap容器
multimap容器 multimap容器保存的是有序的键/值对,但是可以保存重复的元素.multimap中会出现具有相同键值的元素序列.multimap大部分成员函数的使用方式和map相同.因为重复 ...
- HoG / SIFT 学习指北
本文 OI / ACM 无关. Explain HoG 原文出处: N. Dalal, and B. Triggs, Histograms of oriented gradients for huma ...
- js剪贴板应用clipboardData
clipboardData 对象 提供了对剪贴板的访问. 三个方法 1.clearData(sDataFormat) 删除剪贴板中指定格式的数据. 2.getData(sDataFormat) 从剪贴 ...
- [ABC279G] At Most 2 Colors
Problem Statement There is a grid with $1 \times N$ squares, numbered $1,2,\dots,N$ from left to rig ...
- Activity发送信息给Fragment
在MainActivity中设置发送的信息,在fragment中接收, @Override public void onClick(View view) { switch (view.getId()) ...
- 16、strconv
1.strconv是什么? strconv是用来处理字符串和基本类型之间的转换的 2.strconv的使用 /** * @author ly (个人博客:https://www.cnblogs.com ...
- 实用指南:打造卓越企业BI实施解决方案
前言 随着大数据时代的到来,商业智能(BI)工具变得非常重要.一个全面的商业智能方案可以支持数据驱动的决策并提高决策效率,同时还可以准确反映企业运行状态,为企业持续增长提供新的动力.本文小编将为大家介 ...
- pytest框架中conftest.py的作用
conftest.py 是 pytest 框架中的一个特殊文件.它允许你为测试提供自定义的配置和钩子函数.以下是 conftest.py 的主要作用: 提供全局配置:你可以在 conftest.py ...
- idea2020下载、安装、破解、配置
idea2020下载.安装.破解.配置 idea2020下载 [推荐]官方下载地址:https://www.jetbrains.com/idea/download/other.html 进入后往下找, ...
- Python——第一章:用户交互
变量 = input(提示语)首先会在屏幕中显示出提示语, 用户输入内容. 然后把用户输入的内容交给前面的变量 案例1: a = input("请输入第一个数字:") #括号里是提 ...