compare bilateral

This commit is contained in:
odebeir
2012-10-30 16:55:05 +01:00
parent 07f7c2d57e
commit 1460d7f1b1
2 changed files with 86 additions and 11 deletions
+23 -11
View File
@@ -1,9 +1,23 @@
"""
==============================
Simplified bilateral filtering
Bilateral mean
==============================
This example compares
to complete
* local mean
* percentile mean
* bilateral mean
build on the local histogram distribution
local mean uses all pixels belonging to the structuring element to compute average gray level,
percentile mean uses only values between percentiles p0 and p1 (here 10% and 90%),
whereas bilateral mean uses only pixels of the structuring element having a gray level situated inside
g-s0 and g+s1 (here g-500 and g+500).
The filters are applied on a 16 bit image (actual bitdepth is 12bit).
Percentile and usual mean give here similar results, these filters smooth the complete image (background and details).
Bilateral mean exhibits a high filtering rate for continuous area (i.e. background) while image higher frequencies
remains untouched.
"""
import numpy as np
@@ -13,23 +27,21 @@ from skimage import data
from skimage.morphology import disk
import skimage.filter.rank as rank
a8 = (data.coins()).astype('uint8')
a16 = (data.coins()).astype('uint16')*16
selem = np.ones((20,20),dtype='uint8')
f1 = rank.percentile_mean(a8,selem = selem,p0=.1,p1=.9)
selem = disk(20)
f1 = rank.percentile_mean(a16,selem = selem,p0=.1,p1=.9)
f2 = rank.bilateral_mean(a16,selem = selem,s0=500,s1=500)
selem = disk(50)
f3 = rank.equalize(a16,selem = selem)
f3 = rank.mean(a16,selem = selem)
# display results
fig, axes = plt.subplots(nrows=3, figsize=(15,15))
fig, axes = plt.subplots(nrows=3, figsize=(15,10))
ax0, ax1, ax2 = axes
ax0.imshow(np.hstack((a8,f1)))
ax0.imshow(np.hstack((a16,f1)))
ax0.set_title('percentile mean')
ax1.imshow(np.hstack((a16,f2)))
ax1.set_title('bilateral mean')
ax2.imshow(np.hstack((a16,f3)))
ax2.set_title('local equalization')
ax2.set_title('local mean')
plt.show()