In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to implement extended LBP feature extraction in C++ OpenCV. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
An extended introduction to LBP
After the original LBP was proposed, researchers continue to put forward a variety of improvements and optimizations.
Circular LBP operator
The biggest defect of the basic LBP operator is that it only covers a small area within a fixed radius, which obviously can not meet the needs of textures of different sizes and frequencies. In order to adapt to the texture features of different scales and meet the requirements of grayscale and rotation invariance, Ojala et al improved the LBP operator, extending the 3 × 3 neighborhood to any neighborhood, and using the circular neighborhood instead of the square neighborhood. The improved LBP operator allows any number of pixels in the circular neighborhood with a radius of R. Thus, the LBP operator with P sampling points in a circular region with radius R is obtained.
LBP uniform mode LBP (uniform LBP)
The local LBP operator can produce different binary patterns, and the LBP operator with P sampling points in the circular region with radius R will produce P2 patterns. Obviously, with the increase of the number of sampling points in the neighborhood set, the types of binary patterns increase rapidly. Uniform mode is a binary sequence that changes no more than twice from 0 to 1 or from 1 to 0 (the binary sequence is connected end to end). For example, 10100000 is changed three times, so it is not a uniform pattern. There are 58 uniform pattern in all 8-bit binary numbers. Why propose such a uniform LBP, for example: 20 sampling points in 5 × 5 neighborhood, there are 2 ^ 20 = 1048576 binary modes. So many binary patterns are disadvantageous not only for texture extraction, but also for texture recognition, classification and information access. At the same time, too many kinds of patterns are disadvantageous to the expression of texture. For example, when LBP operator is used in texture classification or face recognition, the statistical histogram of LBP pattern is often used to express image information, and more patterns will make the amount of data too large and the histogram too sparse. Therefore, it is necessary to reduce the dimension of the original LBP mode, so that the information of the image can be best represented when the amount of data is reduced.
In order to solve the problem of too many binary patterns and improve the statistics, Ojala proposed an "equivalent pattern" (Uniform Pattern) to reduce the dimension of the pattern types of LBP operators. Ojala et al believe that in real images, most LBP modes contain at most two jumps from 1 to 0 or from 0 to 1. Therefore, Ojala defines the "equivalent pattern" as: when the cyclic binary number corresponding to a LBP jumps from 0 to 1 or from 1 to 0 at most, the binary corresponding to the LBP is called an equivalent pattern class. For example, 00000000 (0 jumps), 00000111 (including only one jump from 0 to 1), and 10001111 (jumping from 1 to 0, then from 0 to 1, for a total of two jumps) are all equivalent pattern classes. All patterns except the equivalent pattern class fall into another category, called the mixed pattern class, such as 10010111 (a total of four jumps). With this improvement, the number of binary patterns is greatly reduced without losing any information. The number of patterns is reduced from 2P to P (Pmur1) + 2, where P represents the number of sampling points in the neighborhood set. For the 8 sampling points in the 3 × 3 neighborhood, the binary pattern is reduced from 256 to 58, that is, it divides the values into 59 categories, 58 uniform pattern as one class, and all other values as 59 classes. In this way, the histogram changes from 256 dimensions to 59 dimensions. This makes the dimension of the feature vector less, and can reduce the impact of high-frequency noise.
Rotation invariant mode LBP
Rotation invariant mode LBP can get the same result when the image is tilted to a certain extent. Its definition can be seen below (Note: this figure is from the network):
We see that the neighbor of the central point is no longer the eight points above and below it (to add, it is not necessarily the neighborhood of 3: 3, which is determined by itself, but the larger neighborhood means the increase of the vector dimension of the histogram), but a circle with it as the center of the circle, specifying the radius of the circle and the number of points, the coordinates of each point can be obtained, but the coordinates of the points are not necessarily integers. If it is an integer, then the pixel value of this point is the value of the corresponding point, and if it is not an integer, it is obtained by difference. From the definition of LBP, we can see that the LBP operator is grayscale invariant, but not rotation invariant. The rotation of the image will get different LBP values. Maenpaa et al. extended the LBP operator and proposed the LBP operator with rotation invariance, that is, constantly rotating the circular neighborhood to get a series of initially defined LBP values, taking the minimum value as the LBP value of the neighborhood.
As shown above (note: this figure comes from the network) gives a schematic diagram of the process of finding the rotation-invariant LBP. The number below the operator in the figure represents the corresponding LBP value of the operator. The eight LBP modes shown in the figure, after rotation-invariant processing, the final rotation-invariant LBP value is 15. In other words, the rotation-invariant LBP mode corresponding to the eight LBP modes in the figure is 00001111.
The steps for extracting LBP feature vectors from several different versions of LBP are described above, as follows:
The detection window is divided into 16 × 16 small areas (cell)
For one pixel in each cell, the grayscale value of the adjacent 8 pixels is compared with it. If the surrounding pixel value is greater than the center pixel value, the position of the pixel is marked as 1, otherwise it is 0. In this way, the 8 points in the neighborhood of 3 to 3 can produce 8-bit binary numbers, that is, the LBP value of the central pixel of the window.
The histogram of each cell is then calculated, that is, the frequency at which each number (assumed to be a decimal LBP value) occurs; then the histogram is normalized.
Finally, the statistical histogram of each cell is connected into a feature vector, that is, the LBP texture feature vector of the whole image.
Then SVM or other machine learning algorithms can be used for classification.
Code demonstration
Following the previous project opencv-LBP, because createtrackbar is used in the demonstration of ELBP, we need to load the function, so we move the original Mat to the top, and then define the basic properties of trackbar.
Then add the method to create trackbar under the code
Core method ELBP_DEMO
Then let's run it to see the effect.
You can see the default effect of 3 on the right. Let's change the radius value to see what the different effects are.
The picture above is when the value is 5.
The picture above shows that the value is 9.
The image above shows a value of 13:00
The image above shows a value of 17:00
It can be seen that the extended LBP algorithm is more obvious than the basic LBP feature extraction. The writing method in the key code is not easy to understand, and I also have a little knowledge in it. I also do it first and then study it.
Thank you for reading! This is the end of this article on "how to achieve extended LBP feature extraction in C++ OpenCV". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.