Rolling guidance filter¶
| Fact | Value |
|---|---|
| Also called | Rolling guidance, RGF |
| Status | Implemented and tested |
| Family | Nonlinear spatial filters |
| Engine | Science engine |
| Type | Nonlinear, iterative, iterated joint bilateral filtering |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | 3 * sigmaSpace |
| Code | engine/src/pixelnexus_engine/filters/edge_preserving.py, rolling_guidance |
| Operator code | engine/src/pixelnexus_engine/filters/edge_preserving.py, rolling_guidance_representation |
| Packages | OpenCV |
Overview¶
The rolling guidance filter removes small structures, such as texture, fine detail and noise, and keeps large edges sharp, after Zhang, Shen, Xu and Jia. It first blurs everything with a Gaussian of the scale. Then a few joint bilateral filters of the original image, each guided by the last result, let the large edges roll back in. The filter runs in the PixelNexus engine, with OpenCV.
How it works¶
- Blur the image with a Gaussian of the scale.
- Filter the original image with a joint bilateral filter guided by the blur.
- Use the result as the new guide, and repeat.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): The image
- \(J^t\): The guide after step t
- \(\sigma_s\): The scale
- \(\sigma_r\): The color sigma
- \(K_p\): The sum of the weights at p
I is the image and J the guide. The first step is a Gaussian blur of sigma s, which removes every structure smaller than the scale, and blurs large edges too. Each further step is a joint bilateral filter of the original image. Neighbors q weigh by their distance from p, and by how close the guide's colors at p and q are. K p is the sum of the weights. Where the blurred guide still shows a large edge, the weights follow it, and the edge comes back sharp from I. Small structures were wiped from the guide, so nothing brings them back. That is the rolling of the guidance.
The first step decides what survives. The Gaussian blur wipes out every structure smaller than the scale, and blurs the large ones. Later steps are joint bilateral filters of the original image, whose color weights come from the guide. Where the guide still shows a large edge, the weights follow it, and the edge comes back sharp. The small structures are gone from the guide, so nothing brings them back.
Kernel or operator¶
There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Scale sigmaSpace |
3 | 0.5 to 20 px | The spatial sigma s. Structures smaller than about this scale are removed. OpenCV uses 3. |
Color sigma sigmaColor |
25 | 1 to 255 levels | The color sigma r of the joint bilateral filters. OpenCV uses 25. |
Iterations iterations |
4 | 1 to 10 | The number of steps, the first one included. OpenCV uses 4. |
Start start |
Gaussian blur, as in the paper | Gaussian blur, as in the paper, The image, as in OpenCV | Zhang et al. start with a Gaussian blur, which removes small structures before the edges come back. OpenCV's rollingGuidanceFilter starts from the image itself, so its first step is an ordinary bilateral filter. |
Implementation¶
rolling_guidance in engine/src/pixelnexus_engine/filters/edge_preserving.py has two starts. The paper start blurs the image with cv2.GaussianBlur and then runs cv2.ximgproc.jointBilateralFilter for the remaining steps. The OpenCV start calls cv2.ximgproc.rollingGuidanceFilter. Its source starts the guide from the image itself, not from a blur. So its first step is an ordinary bilateral filter, which keeps small structures with strong edges.
Worked example¶
| Start | Color sigma | PSNR (dB) |
|---|---|---|
| paper | 25 | 34.07 |
| paper | 50 | 33.71 |
| opencv | 25 | 24.59 |
| opencv | 50 | 24.76 |
The image of the figure, with the other defaults. The PSNR compares the result with the same image without the dots, so it is higher when more of the dots are gone. The input itself scores 24.61 dB.
This example has no noise. It shows the purpose of the filter, removing small structures. With the paper start, the dots go and the PSNR against the image without dots rises from 24.61 dB to 34.07 dB. With OpenCV's start, the dots stay, and the PSNR does not move. Their edges are strong, so the bilateral steps keep them. At a scale of 1.5, the dots, 2 pixels wide, are about as large as the scale, so they stay too.
Complexity¶
- Time: \(O(N K S^2)\)
- Memory: \(O(N)\)
N is the number of pixels, K the number of steps and S the side of the bilateral window.
Artifacts and limitations¶
Limitations
- Small objects with strong edges also vanish, since only their size counts.
- Slow for large scales.
Artifacts
- Rounded corners on large shapes.
Tests¶
The OpenCV start must equal rollingGuidanceFilter, and the paper start a Gaussian blur followed by joint bilateral filters. On a grid of small dots, the paper start must remove the dots and the OpenCV start must keep them. The representation must have its three stages for both starts.
References¶
- Zhang, Q., Shen, X., Xu, L., and Jia, J. Rolling guidance filter. European Conference on Computer Vision (ECCV), Lecture Notes in Computer Science, 815 to 830, 2014. DOI 10.1007/978-3-319-10578-9_53.
- OpenCV documentation, cv::ximgproc::rollingGuidanceFilter and jointBilateralFilter.