In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the filtering principle of the guide diagram and the implementation of OpenCV. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The guide graph filter is an adaptive weight filter, which can keep the boundary while smoothing the image. Here only talk about the adaptive weight principle, C++ to achieve grayscale images and color images of the pilot image filtering, verification results.
Adaptive weight principle
As a linear filter, bootstrap filter can be simply defined in the following form:
Where I is the guide image (guided Image), P is the input image to be filtered, Q is the filtered output image, and W is the weight value determined according to the guide diagram I. The weight value W can be expressed by the following formula (derived in detail in the original literature):
μ k is the mean value of pixels in the window, Ii and Ij refer to the values of two adjacent pixels, σ k represents the variance of pixels in the window, and ε is a penalty value. The adaptive weight can be obtained according to the above analysis: when Ii and Ij are on both sides of the boundary, (Ii- μ k) and (Ij- μ k) have different signs, otherwise, they will have the same sign. On the other hand, the weight value of the different sign will be much smaller than that of the same sign, so the pixels in the flat area will be given more weight, and the smoothing effect will be more obvious, while the pixels on both sides of the boundary will be given less weight. the smoothing effect is weak and can maintain the boundary.
The penalty value ε also has a great influence on the filtering effect, when the ε value is very small, the filtering is as described above; when the ε value is very large, the calculation formula of the weight will be approximate to a mean filter, and the smoothing effect will be more obvious.
At the same time, we can also look at the adaptive weight principle of the guide graph filter according to the linear filtering formula, the local linear filtering model formula is as follows:
I refers to the boot image, Q is the output image, and the two coefficients of ak and bk are determined according to the boot image I and the input image P. If we calculate the gradient on both sides of the above formula, we can get ▽ Qartia * ▽ I, that is, the gradient information of the output image is completely determined by the gradient information of the guide image. When there is a boundary in the guide image, the corresponding position in the output image will also have a boundary. The values of an and b will determine the weight of gradient information and smoothing information.
By observing the formulas of an and b, the numerator of an is the covariance of I and P, the denominator part is the variance of I plus the truncation value ε, and the value of b is the mean of P minus the mean of a multiplied by I. It can be seen that when a value is very small, b is about equal to the mean competition of pixels in the window, which is similar to mean filtering; while when a value is very large, the output mainly depends on the size of a * ▽ I, and the gradient information can be retained.
C++ realizes Boot Image filtering of Grayscale Image and Color Image
According to the pseudo code provided in the original literature, it is not difficult to implement the bootstrap image filtering algorithm with C++. The pseudo code is as follows:
The difference is that when finding a, the original variance σ is replaced by the covariance 3x3 matrix ∑ k, which is expressed as follows:
U is the 3x3 unit matrix, and the a will no longer be a value, but a vector of 1 to 3, and then b will be found. An is a vector of 1 to 3, μ k is a vector of 3 to 1, and multiplying b is a constant, from which the value of the constant b can be obtained.
There are two situations here:
The ① input diagram is a single channel: just follow the above steps to calculate.
The ② input diagram consists of three channels: first, the three channels are separated, each channel is filtered, and then the channels are merged.
Note: the color image of the guide image is grayscale than the guide image, and the boundary protection is more obvious, see the original text.
Effect verification
The average part of the code can be realized by the boxFilter () function in OpenCV or the blur () function. In short, it is a mean filter, which has nothing to do with the size of the window, because the mean filtering realized by histogram can greatly reduce the operation time. The code for the VS2015+OpenCV3.4.0 implementation is placed on my cloud code: https://gitee.com/rxdj/guidedFilter.git.
The main input parameters are guide diagram I, input graph P, window radius r, truncation value ε, and the output parameter is filtered image Q. The guide graph I and the input image P can be the same or different. For example, the original reference image is often used as the guide map in stereo matching, and the cost space map is filtered to achieve cost aggregation. In this way, the matching cost of the boundary region of the original image can be preserved as much as possible, while the matching cost of smooth and flat region can be preserved as much as possible.
(note: the code in the literature is written through matlab, and when the image is read in matlab, the image will be automatically normalized to 0-1, so the setting of truncation value ε is much smaller, such as 0.1. However, there is no normalization operation after reading the image in this paper, so the setting of truncation value ε will be different. If you need normalization, you can read the image yourself and divide it by 255).
Single channel grayscale image
Change the cutoff value ε
Rust 10, ε = 0 rn 10, ε = 100
R = 10, ε = 2000, ε = 8000
Change the window radius r
R = 0, ε = 500, r = 500
R = 10, ε = 500, r = 20, ε = 500
Three-channel color diagram
Original drawing
Fast Guide Graph filtering algorithm
See the fast bootstrap map filtering algorithm. The speed is mainly based on the idea of image pyramid. The steps are as follows:
The guide image I and the input image P are downsampled by 1max s to get the I image, P'.
The coefficients an and b are calculated by using I 'and P', and the output image Q' is calculated.
Q' is upsampled by s times to get the final output image Q.
Because the calculation part is a downsampled image, the amount of computation will be greatly reduced without introducing obvious distortion, so it becomes a fast guide image filtering. For the code, please see the fastGuidedFilter branch of the code link above.
On the principle of bootstrap filtering and OpenCV implementation is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it 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: 205
*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.