mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 07:11:57 +08:00
moved example to doc
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
==============================
|
||||
Simplified bilateral filtering
|
||||
==============================
|
||||
|
||||
to complete
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.morphology import disk
|
||||
import skimage.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)
|
||||
f2 = rank.bilateral_mean(a16,selem = selem,s0=500,s1=500)
|
||||
selem = disk(50)
|
||||
f3 = rank.equalize(a16,selem = selem)
|
||||
|
||||
# display results
|
||||
fig, axes = plt.subplots(nrows=3, figsize=(15,5))
|
||||
ax0, ax1, ax2 = axes
|
||||
|
||||
ax0.imshow(np.hstack((a8,f1)))
|
||||
ax1.imshow(np.hstack((a16,f2)))
|
||||
ax2.imshow(np.hstack((a16,f3)))
|
||||
|
||||
plt.show()
|
||||
@@ -1,3 +1,20 @@
|
||||
"""
|
||||
==============================
|
||||
Compare execution time for
|
||||
- skimage.rank.median,
|
||||
- skimage.filter import median_filter
|
||||
- scipy.ndimage.filters import percentile_filter,
|
||||
|
||||
and
|
||||
|
||||
- skimage.cmorph.dilate
|
||||
- skimage.rank.maximum
|
||||
|
||||
==============================
|
||||
|
||||
to complete
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
@@ -17,7 +34,6 @@ def log_timing(func):
|
||||
res = func(*arg)
|
||||
t2 = time.time()
|
||||
ms = (t2-t1)*1000.0
|
||||
print '%s took %0.3f ms' % (func.func_name, ms)
|
||||
return (res,ms)
|
||||
return wrapper
|
||||
|
||||
@@ -26,6 +42,14 @@ def log_timing(func):
|
||||
def cr_med(image,selem):
|
||||
return rank.median(image=image,selem = selem)
|
||||
|
||||
@log_timing
|
||||
def cr_max(image,selem):
|
||||
return rank.maximum(image=image,selem = selem)
|
||||
|
||||
@log_timing
|
||||
def cm_dil(image,selem):
|
||||
return dilation(image=image,selem = selem)
|
||||
|
||||
@log_timing
|
||||
def ctmf_med(image,radius):
|
||||
return median_filter(image=image,radius=radius)
|
||||
@@ -46,13 +70,12 @@ def compare_dilate():
|
||||
rec = []
|
||||
e_range = range(1,20,1)
|
||||
for r in e_range:
|
||||
# elem = np.ones((r,r),dtype='uint8')
|
||||
elem = disk(r+1)
|
||||
# elem = (np.random.random((r,r))>.5).astype('uint8')
|
||||
rc,ms_rc = cr_max(a,elem)
|
||||
rcm,ms_rcm = cm_dil(a,elem)
|
||||
rec.append((ms_rc,ms_rcm))
|
||||
# check if results are identical
|
||||
# same structuring element, the results must match
|
||||
assert (rc==rcm).all()
|
||||
|
||||
rec = np.asarray(rec)
|
||||
@@ -65,7 +88,6 @@ def compare_dilate():
|
||||
plt.imshow(np.hstack((rc,rcm)))
|
||||
|
||||
r = 9
|
||||
# elem = np.ones((r,r),dtype='uint8')
|
||||
elem = disk(r+1)
|
||||
|
||||
rec = []
|
||||
@@ -75,6 +97,7 @@ def compare_dilate():
|
||||
(rc,ms_rc) = cr_max(a,elem)
|
||||
(rcm,ms_rcm) = cm_dil(a,elem)
|
||||
rec.append((ms_rc,ms_rcm))
|
||||
# same structuring element, the results must match
|
||||
assert (rc==rcm).all()
|
||||
|
||||
rec = np.asarray(rec)
|
||||
@@ -86,7 +109,6 @@ def compare_dilate():
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((rc,rcm)))
|
||||
|
||||
plt.show()
|
||||
|
||||
def compare_median():
|
||||
""" Comparison between
|
||||
@@ -145,7 +167,8 @@ def compare_median():
|
||||
plt.ylabel('time (ms)')
|
||||
plt.xlabel('image size')
|
||||
|
||||
plt.show()
|
||||
if __name__ == '__main__':
|
||||
# compare_dilate()
|
||||
compare_median()
|
||||
|
||||
|
||||
compare_dilate()
|
||||
compare_median()
|
||||
plt.show()
|
||||
@@ -1,31 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.morphology import disk
|
||||
import skimage.rank as rank
|
||||
|
||||
if __name__ == '__main__':
|
||||
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)
|
||||
f2 = rank.bilateral_mean(a16,selem = selem,s0=500,s1=500)
|
||||
|
||||
selem = disk(50)
|
||||
f3 = rank.equalize(a16,selem = selem)
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((a8,f1)))
|
||||
plt.colorbar()
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((a16,f2)))
|
||||
plt.colorbar()
|
||||
|
||||
plt.figure()
|
||||
plt.imshow(np.hstack((a16,f3)))
|
||||
plt.colorbar()
|
||||
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user