局部二值模式LBP(Local Binary Pattern)实现代码
来源:互联网 发布:从java走向javaee 编辑:程序博客网 时间:2024/05/22 04:36
局部二值模式LBP由于其简单、高效在目标检测、目标识别、图像检索等领域得到了广泛的应用。现如今,LBP的变体不下上十种,如VLBP、SILBP等。要了解更多关于LBP的知识可以参考:纹理分类-全局特征LBP及相关文献。
2)带有容忍银子的LBP算子
3)带有乘性因子的LBP算子
欲了解更多参考论文:Modeling Pixel Process with Scale Invariant Local Patterns for Background Subtraction in Complex Scenes。
下面介绍的三种LBP算子的区别见下图:
本文不介绍LBP的理论知识,只是简单的说说LBP及其变体的实现:
1)最原始的LBP算子的实现代码
- void lbp( Mat& _src, Mat& _dst)
- {
- if ( -_dst.empty())
- _dst.create(_src.rows, _src.cols, CV_8UC1);
- _dst = cv::Scalar::all(0);
- // calculate patterns
- for(int i=1;i<_src.rows-1;i++)
- {
- for(int j=1;j<_src.cols-1;j++)
- {
- uchar center = _src.at<uchar>(i,j);
- unsigned char code = 0;
- code |= (_src.at<uchar>(i-1,j-1) >= center) << 7;
- code |= (_src.at<uchar>(i-1,j) >= center) << 6;
- code |= (_src.at<uchar>(i-1,j+1) >= center) << 5;
- code |= (_src.at<uchar>(i,j+1) >= center) << 4;
- code |= (_src.at<uchar>(i+1,j+1) >= center) << 3;
- code |= (_src.at<uchar>(i+1,j) >= center) << 2;
- code |= (_src.at<uchar>(i+1,j-1) >= center) << 1;
- code |= (_src.at<uchar>(i,j-1) >= center) << 0;
- _dst.at<unsigned char>(i,j) = code;
- }
- }
- }
- void lbp_with_factor( Mat& _src, Mat& _dst, uchar factor) // factor default 3
- {
- if ( -_dst.empty())
- _dst.create(_src.rows, _src.cols, CV_8UC1);
- _dst = cv::Scalar::all(0);
- // calculate patterns
- for(int i=1;i<_src.rows-1;i++)
- {
- for(int j=1;j<_src.cols-1;j++)
- {
- uchar center = _src.at<uchar>(i,j)+factor;
- unsigned char code = 0;
- code |= (_src.at<uchar>(i-1,j-1) >= center) << 7;
- code |= (_src.at<uchar>(i-1,j) >= center) << 6;
- code |= (_src.at<uchar>(i-1,j+1) >= center) << 5;
- code |= (_src.at<uchar>(i,j+1) >= center) << 4;
- code |= (_src.at<uchar>(i+1,j+1) >= center) << 3;
- code |= (_src.at<uchar>(i+1,j) >= center) << 2;
- code |= (_src.at<uchar>(i+1,j-1) >= center) << 1;
- code |= (_src.at<uchar>(i,j-1) >= center) << 0;
- _dst.at<unsigned char>(i,j) = code;
- }
- }
- }
- // 这里需要采用2个字符来编码,如00、01、10、11
- void lbp_with_factor( Mat& _src, Mat& _dst, float factor) // facotr default 0.1
- {
- if ( -_dst.empty())
- _dst.create(_src.rows, _src.cols, CV_8UC1);
- _dst = cv::Scalar::all(0);
- // calculate patterns
- for(int i=1;i<_src.rows-1;i++)
- {
- for(int j=1;j<_src.cols-1;j++)
- {
- uchar center = _src.at<uchar>(i,j);
- int up = center*(1.0+factor);
- int down = center*(1.0+factor);
- unsigned char code = 0;
- /*code |= (_src.at<uchar>(i-1,j-1) >= center ) << 7;
- code |= (_src.at<uchar>(i-1,j) >= center) << 6;
- code |= (_src.at<uchar>(i-1,j+1) >= center) << 5;
- code |= (_src.at<uchar>(i,j+1) >= center) << 4;
- code |= (_src.at<uchar>(i+1,j+1) >= center) << 3;
- code |= (_src.at<uchar>(i+1,j) >= center) << 2;
- code |= (_src.at<uchar>(i+1,j-1) >= center) << 1;
- code |= (_src.at<uchar>(i,j-1) >= center) << 0;
- _dst.at<unsigned char>(i,j) = code;*/
- }
- }
- }
阅读全文
0 0
- 局部二值模式LBP(Local Binary Pattern)实现代码
- 局部二值模式LBP(Local Binary Pattern)实现代码
- LBP(Local Binary Pattern,局部二值模式)
- LBP Local Binary Pattern 局部二值模式 资料整理
- 纹理特征LBP(local binary pattern,局部二值模式)
- LBP (local binary mode)局部二值模式 纹理描述
- LBP: Local Binary Patterns 局部二进模式Matlab实现
- LBP(Local Binary Patterns)局部二进制模式
- 局部二进制模式(Local Binary Patterns,LBP)——MATLAB实现
- LBP(local binary pattern)
- [转]LBP笔记(Local Binary Pattern)
- 关于LBP(Local Binary Pattern)特征
- LBP(局部二值模式)实现人脸识别
- 局部二值模式(LBP)理论学习与算法实现
- LBP(Local Binary Pattern)特征
- 局部二值模式(LBP)
- LBP(局部二值模式)
- 关于LBP(Local Binary Pattern)特征<二> 几种变种
- Visual studio 2017中 Javascript无法智能提示的解决办法
- 判断今天是星期几 暴力枚举
- Retrofit各个注解的含义及作用
- [刷题]Codeforces Round #393(Div. 2)
- OJ提交题目中的语言选项里G++与C++的区别
- 局部二值模式LBP(Local Binary Pattern)实现代码
- 计算机网络名词解释大全
- 阿里云服务器 centos web服务器 apache日志监控命令
- Scala 隐式转换规则
- PHP编译时报错error: mysql configure failed.以及/usr/bin/ld: cannot find -lmysqlclient
- 使用0和false犯得错误
- mysql中concat的用法
- vue-cli 整个流程简单学习
- C++ 值传递、指针传递、引用传递详解