示例#1
0
def test_eagle():
    """ Test that "eagle" image can be loaded. """
    # Fetching the data through the testing module will
    # cause the test to skip if pooch isn't installed.
    fetch('data/eagle.png')
    eagle = data.eagle()
    assert_equal(eagle.ndim, 2)
    assert_equal(eagle.dtype, np.dtype('uint8'))
See Wikipedia_ for more details on the algorithm.

.. _Wikipedia: https://en.wikipedia.org/wiki/Watershed_(image_processing)

"""

from scipy import ndimage as ndi
import matplotlib.pyplot as plt

from skimage.morphology import disk
from skimage.segmentation import watershed
from skimage import data
from skimage.filters import rank
from skimage.util import img_as_ubyte

image = img_as_ubyte(data.eagle())

# denoise image
denoised = rank.median(image, disk(2))

# find continuous region (low gradient -
# where less than 10 for this image) --> markers
# disk(5) is used here to get a more smooth image
markers = rank.gradient(denoised, disk(5)) < 10
markers = ndi.label(markers)[0]

# local gradient (disk(2) is used to keep edges thin)
gradient = rank.gradient(denoised, disk(2))

# process the watershed
labels = watershed(gradient, markers)
示例#3
0
def test_eagle():
    """ Test that "eagle" image can be loaded. """
    eagle = data.eagle()
    assert_equal(eagle.ndim, 2)
    assert_equal(eagle.dtype, np.dtype('uint8'))
 def setup(self):
     try:
         self.image = data.eagle()
     except ValueError:
         raise NotImplementedError("eagle data unavailable")
     self.image_float32 = self.image.astype(np.float32)