Using the bilateral filter

The bilateral filter is an edge-preserving smoothing filter. For this filter, the center pixel is set to the weighted average of the pixel values of some of its neighbors only the ones with roughly similar brightness as the center pixel. In this section, we shall see how we can use scikit-image package's bilateral filter implementation to denoise an image. Let us first start by creating a noisy image from the following gray scale mountain image:

The following code block demonstrates how to use the numpy random_noise()function:

im = color.rgb2gray(img_as_float(io.imread('../images/mountain.png')))
sigma = 0.155
noisy = random_noise(im, var=sigma**2)
pylab.imshow(noisy)

The following screenshot shows the noisy image created by adding random noise with the original image using the previous code:

The following code block demonstrates how to use the bilateral filter to denoise the previous noisy image, with different values for the parameters, σcolor and σspatial:

pylab.figure(figsize=(20,15))
i = 1
for sigma_sp in [5, 10, 20]:
for sigma_col in [0.1, 0.25, 5]:
pylab.subplot(3,3,i)
pylab.imshow(denoise_bilateral(noisy, sigma_color=sigma_col,
sigma_spatial=sigma_sp, multichannel=False))
pylab.title(r'$sigma_r=$' + str(sigma_col) + r', $sigma_s=$' + str(sigma_sp), size=20)
i += 1
pylab.show()

The following screenshot shows the output of the previous code. As can be seen, if the standard deviation is higher, the image gets less noisy but more blurred. It takes a few minutes to execute the previous code block, as the implementation is even slower on RGB images:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.136.165