目录

OpenCV——多分辨率LBP的计算方法由CSDN点云侠原创,爬虫自重。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫。
一、算法原理
1、原理概述
基本LBP算子虽然在早期的实验中取得了一系列成果,但是应用于不同领域的具体问题时,该算子的处理结果并不能达到预期的效果。因此,很多学者对其进行了改进,并取得了显著成果。改进算子主要有多分辨率LBP、旋转不变LBP和等价LBP等。
  TimoOjala等_对基本LBP进行拓展,拓展后的多分辨率LBP不再仅仅是 
     
      
       
       
         3 
        
       
         × 
        
       
         3 
        
       
      
        3\times3 
       
      
    3×3格网,而是可以设置邻域像素数量和半径,通常用 
     
      
       
       
         P 
        
       
      
        P 
       
      
    P表示邻域像素个数,用 
     
      
       
       
         R 
        
       
      
        R 
       
      
    R表示半径,记为LBP_PR;与此同时,运用了插值的思想,将邻域窗口由方形拓展为圆形。基本LBP是邻域像素数量P=8,半径R=1.0的版本。下图描述了P和R取不同值时的情况。
 
2、参考文献
二、代码实现
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
// 多分辨率LBP
cv::Mat ExpandLocalBinaryPattern(cv::Mat& orignImg, int lbpRadius = 3, int maxCount = 20)
{
	cv::Mat grayImg;
	cvtColor(orignImg, grayImg, cv::COLOR_BGR2GRAY);
	int offset = lbpRadius * 2;
	cv::Mat elbpImg = cv::Mat::zeros(grayImg.rows - offset, grayImg.cols - offset, CV_8UC1);
	int numNeighbor = 8;
	for (int n = 0; n < numNeighbor; n++)
	{
		float x = lbpRadius * cos((2 * CV_PI * n) / numNeighbor);
		float y = lbpRadius * (-sin((2 * CV_PI * n) / numNeighbor));
		int fx = static_cast<int>(floor(x)); // 向下取整,它返回的是小于或等于函数参数,并且与之最接近的整数
		int fy = static_cast<int>(floor(y));
		int cx = static_cast<int>(ceil(x));  // 向上取整,它返回的是大于或等于函数参数,并且与之最接近的整数
		int cy = static_cast<int>(ceil(y));
		float ty = y - fy;
		float tx = x = fx;
		float w1 = (1 - tx) * (1 - ty);
		float w2 = (tx) * (1 - ty);
		float w3 = (1 - tx) * (ty);
		float w4 = (tx) * (ty);
		for (int row = lbpRadius; row < (grayImg.rows - lbpRadius); row++)
		{
			for (int col = lbpRadius; col < (grayImg.cols - lbpRadius); col++)
			{
				float t = w1 * grayImg.at<uchar>(row + fy, col + fx) +
					w2 * grayImg.at<uchar>(row + fy, col + cx) +
					w3 * grayImg.at<uchar>(row + cy, col + fx) +
					w4 * grayImg.at<uchar>(row + cy, col + cx);
				elbpImg.at<uchar>(row - lbpRadius, col - lbpRadius) +=
					((t > grayImg.at<uchar>(row, col)) && (abs(t - grayImg.at<uchar>(row, col)) > std::numeric_limits<float>::epsilon())) << n;
			}
		}
	}
	
	return elbpImg;
}
int main(int argc, char** argv)
{
	cv::Mat img = cv::imread("luna.png");
	//cv::Mat img;
	//resize(img, img, cv::Size(800, 500), 0, 0, cv::INTER_AREA);
	if (img.empty())
	{
		cout << "请确认图像文件名称是否正确" << endl;
		return -1;
	}
	imshow("img", img);
	// 多分辨率LBP
	cv::Mat lbpImg = ExpandLocalBinaryPattern(img);
	imshow("多分辨率LBP", lbpImg);
	cv::waitKey(0);
	return 0;
}
三、结果展示











