Skip to content

Commit a1c72e9

Browse files
committed
review denoise
1 parent 4ee7d30 commit a1c72e9

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed
Loading
Loading
Binary file not shown.

source/py_tutorials/py_photo/py_non_local_means/py_non_local_means.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Theory
1818

1919
In earlier chapters, we have seen many image smoothing techniques like Gaussian Blurring, Median Blurring etc and they were good to some extent in removing small quantities of noise. In those techniques, we took a small neighbourhood around a pixel and did some operations like gaussian weighted average, median of the values etc to replace the central element. In short, noise removal at a pixel was local to its neighbourhood.
2020

21-
There is a property of noise. Noise is generally considered to be a random variable with zero mean. Consider a noisy pixel, :math:`p = p_0 + n` where :math:`p_0` is the true value of pixel and :math:`n` is the noise in that pixel. You can a large number of same pixel (say :math:`N`) from different images and computes their average. Ideally, you should get :math:`p = p_0` since mean of noise is zero.
21+
There is a property of noise. Noise is generally considered to be a random variable with zero mean. Consider a noisy pixel, :math:`p = p_0 + n` where :math:`p_0` is the true value of pixel and :math:`n` is the noise in that pixel. You can take large number of same pixels (say :math:`N`) from different images and computes their average. Ideally, you should get :math:`p = p_0` since mean of noise is zero.
2222

23-
You can verify it yourself by a simple setup. Hold a static camera to a certain location for a couple of seconds. This will give you plenty of frames, or a lot of images of the same scene. Then write a piece of code to find the average of all the frames in the video (This should be too simple for you now ). Compare the final result and first frame. Unfortunately this simple method is not robust to camera and scene motions. Also often there is only one noisy image available.
23+
You can verify it yourself by a simple setup. Hold a static camera to a certain location for a couple of seconds. This will give you plenty of frames, or a lot of images of the same scene. Then write a piece of code to find the average of all the frames in the video (This should be too simple for you now ). Compare the final result and first frame. You can see reduction in noise. Unfortunately this simple method is not robust to camera and scene motions. Also often there is only one noisy image available.
2424

2525
So idea is simple, we need a set of similar images to average out the noise. Consider a small window (say 5x5 window) in the image. Chance is large that the same patch may be somewhere else in the image. Sometimes in a small neigbourhood around it. What about using these similar patches together and find their average? For that particular window, that is fine. See an example image below:
2626

@@ -97,12 +97,18 @@ Now we will apply the same method to a video. The first argument is the list of
9797
# convert all to grayscale
9898
gray = [cv2.cvtColor(i, cv2.COLOR_BGR2GRAY) for i in img]
9999

100+
# convert all to float64
101+
gray = [np.float64(i) for i in gray]
102+
100103
# create a noise of variance 25
101-
noise = np.uint8(np.random.randn(*gray[1].shape)*5)
104+
noise = np.random.randn(*gray[1].shape)*10
102105

103106
# Add this noise to images
104107
noisy = [i+noise for i in gray]
105108

109+
# Convert back to uint8
110+
noisy = [np.uint8(np.clip(i,0,255)) for i in noisy]
111+
106112
# Denoise 3rd frame considering all the 5 frames
107113
dst = cv2.fastNlMeansDenoisingMulti(noisy, 2, 5, None, 4, 7, 35)
108114

@@ -114,7 +120,7 @@ Now we will apply the same method to a video. The first argument is the list of
114120

115121
Below image shows a zoomed version of the result we got:
116122

117-
.. image:: images/nlm_video.jpg
123+
.. image:: images/nlm_multi.jpg
118124
:alt: Denoising a frame
119125
:align: center
120126

@@ -127,7 +133,7 @@ Additional Resources
127133

128134
#. http://www.ipol.im/pub/art/2011/bcm_nlm/ (It has the details, online demo etc. Highly recommended to visit. Our test image is generated from this link)
129135

130-
#. Online course at coursera (link to be added)(First image taken from here)
136+
#. `Online course at coursera <https://www.coursera.org/course/images>`_ (First image taken from here)
131137

132138
Exercises
133139
============

0 commit comments

Comments
 (0)