add comment to bilateral denoising example

This commit is contained in:
Olivier Debeir
2012-10-10 11:29:28 +02:00
parent a7ff15188f
commit d13517035f
3 changed files with 17 additions and 18 deletions
+9 -14
View File
@@ -1,26 +1,22 @@
"""
====================================================
Denoising the picture of Lena using total variation
Denoising the picture of Lena using bilateral filter
====================================================
In this example, we denoise a noisy version of the picture of Lena
using the total variation denoising filter. The result of this filter
is an image that has a minimal total variation norm, while being as
close to the initial image as possible. The total variation is the L1
norm of the gradient of the image, and minimizing the total variation
typically produces "posterized" images with flat domains separated by
sharp edges.
It is possible to change the degree of posterization by controlling
the tradeoff between denoising and faithfulness to the original image.
using an approximation of a bilateral filter.
The pixels used to compute a local mean respect these conditions:
- be close to the central pixel, i.e. belong to the given structuring element.
- have a similar gray level, similarity is fixed by an interval [-s0,+s1] centered on the central pixel gray level.
The filter used is an approximation of a classical bilateral filter in the sens that kernel are usually gaussian
both in spatial and spectral dimensions.
"""
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color, img_as_ubyte
from skimage.filter import tv_denoise
from skimage.rank import bilateral_mean
from skimage.morphology import disk
@@ -44,12 +40,11 @@ plt.axis('off')
plt.title('bilateral denoising', fontsize=20)
selem = disk(30)
bilateral_denoised = bilateral_mean(noisy.astype(np.uint8), selem=selem,s0=30,s1=30)
bilateral_denoised = bilateral_mean(noisy.astype(np.uint8), selem=selem,s0=40,s1=40)
plt.subplot(133)
plt.imshow(bilateral_denoised, cmap=plt.cm.gray, vmin=40, vmax=220)
plt.axis('off')
plt.title('(more) bilateral denoising', fontsize=20)
plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0, left=0,
right=1)
plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0, left=0,right=1)
plt.show()
+7 -3
View File
@@ -24,7 +24,7 @@ import matplotlib.pyplot as plt
from skimage import data
from skimage.filter import threshold_otsu, threshold_adaptive
from skimage.rank import threshold
from skimage.rank import threshold,morph_contr_enh
from skimage.morphology import disk
@@ -38,9 +38,10 @@ binary_adaptive = threshold_adaptive(image, block_size, offset=10)
selem = disk(10)
loc_thresh = threshold(image,selem=selem)
loc_morph_contr_enh = morph_contr_enh(image,selem=selem)
fig, axes = plt.subplots(nrows=4, figsize=(7, 8))
ax0, ax1, ax2, ax3 = axes
fig, axes = plt.subplots(nrows=5, figsize=(7, 8))
ax0, ax1, ax2, ax3, ax4 = axes
plt.gray()
ax0.imshow(image)
@@ -55,6 +56,9 @@ ax2.set_title('Adaptive thresholding')
ax3.imshow(loc_thresh)
ax3.set_title('Local thresholding')
ax4.imshow(loc_morph_contr_enh)
ax4.set_title('Local morphological contrast enhancement')
for ax in axes:
ax.axis('off')
+1 -1
View File
@@ -1,6 +1,6 @@
"""rank.py - rankfilter for local (custom kernel) maximum, minimum, median, mean, auto-level, egalize, etc
The local histogram is computed using a sliding window similar to the method described in
The local histogram is computed using a sliding window similar to the method described in
Reference: Huang, T. ,Yang, G. ; Tang, G.. "A fast two-dimensional median filtering algorithm",
IEEE Transactions on Acoustics, Speech and Signal Processing, Feb 1979. Volume: 27 , Issue: 1, Page(s): 13 - 18.