mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
local Otsu returns now the threshold values
This commit is contained in:
@@ -308,6 +308,56 @@ plt.imshow(ima[200:350,350:450],cmap=plt.cm.gray)
|
||||
plt.subplot(2,2,4)
|
||||
plt.imshow(penh[200:350,350:450],cmap=plt.cm.gray)
|
||||
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
|
||||
Image threshold
|
||||
===============
|
||||
The Otsu's threshold [1]_ method can be applied locally using local greylevel distribution.
|
||||
In the example below, for each pixel, an "optimal" threshold is determined by maximizing
|
||||
the variance between two classes of pixels of the local neighborhood defined by a structuring element.
|
||||
|
||||
The example compares the local threshold with the global threshold `skimage.filter.threshold_otsu``.
|
||||
|
||||
.. note: local threshold is much slower than global one.
|
||||
|
||||
.. [1] http://en.wikipedia.org/wiki/Otsu's_method
|
||||
|
||||
"""
|
||||
from skimage.filter.rank import otsu
|
||||
from skimage.filter import threshold_otsu
|
||||
|
||||
p8 = data.page()
|
||||
|
||||
radius = 10
|
||||
selem = disk(radius)
|
||||
|
||||
# t_loc_otsu is an image
|
||||
t_loc_otsu = otsu(p8,selem)
|
||||
loc_otsu = p8>=t_loc_otsu
|
||||
|
||||
# t_glob_otsu is a scalar
|
||||
t_glob_otsu = threshold_otsu(p8)
|
||||
glob_otsu = p8>=t_glob_otsu
|
||||
|
||||
plt.figure()
|
||||
plt.subplot(2,2,1)
|
||||
plt.imshow(p8,cmap=plt.cm.gray)
|
||||
plt.xlabel('original')
|
||||
plt.colorbar()
|
||||
plt.subplot(2,2,2)
|
||||
plt.imshow(loc_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('local Otsu ($radius=%d$)'%radius)
|
||||
plt.colorbar()
|
||||
plt.subplot(2,2,3)
|
||||
plt.imshow(p8>=loc_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('original>=local Otsu'%t_glob_otsu)
|
||||
plt.subplot(2,2,4)
|
||||
plt.imshow(glob_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('global Otsu ($t=%d$)'%t_glob_otsu)
|
||||
plt.show()
|
||||
|
||||
|
||||
"""
|
||||
.. image:: PLOT2RST.current_figure
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
=====================
|
||||
Local Otsu Threshold
|
||||
=====================
|
||||
This example shows how Otsu's threshold [1]_ method can be applied locally.
|
||||
For each pixel, an "optimal" threshold is determined by maximizing the variance between two classes of pixels
|
||||
of the local neighborhood defined by a structuring element.
|
||||
|
||||
The example compares the local threshold with the global threshold.
|
||||
|
||||
.. note: local threshold is much slower than global one.
|
||||
|
||||
.. [1] http://en.wikipedia.org/wiki/Otsu's_method
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import data
|
||||
from skimage.morphology.selem import disk
|
||||
import skimage.filter.rank as rank
|
||||
from skimage.filter import threshold_otsu
|
||||
|
||||
|
||||
p8 = data.page()
|
||||
|
||||
radius = 10
|
||||
selem = disk(radius)
|
||||
|
||||
loc_otsu = rank.otsu(p8,selem)
|
||||
t_glob_otsu = threshold_otsu(p8)
|
||||
glob_otsu = p8>=t_glob_otsu
|
||||
|
||||
|
||||
plt.figure()
|
||||
plt.subplot(2,2,1)
|
||||
plt.imshow(p8,cmap=plt.cm.gray)
|
||||
plt.xlabel('original')
|
||||
plt.colorbar()
|
||||
plt.subplot(2,2,2)
|
||||
plt.imshow(loc_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('local Otsu ($radius=%d$)'%radius)
|
||||
plt.colorbar()
|
||||
plt.subplot(2,2,3)
|
||||
plt.imshow(p8>=loc_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('original>=local Otsu'%t_glob_otsu)
|
||||
plt.subplot(2,2,4)
|
||||
plt.imshow(glob_otsu,cmap=plt.cm.gray)
|
||||
plt.xlabel('global Otsu ($t=%d$)'%t_glob_otsu)
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user