Addressed a few minor issues raised by Juan and Stefan.

This commit is contained in:
emmanuelle
2015-05-09 10:23:49 +02:00
parent a615623643
commit 1c3af75dd3
2 changed files with 17 additions and 8 deletions
+11 -8
View File
@@ -5,21 +5,21 @@ from ..filters import gaussian_filter
def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2,
volume_fraction=0.5, seed=None):
"""
Generate synthetic binary image with several blob-like rounded objects.
Generate synthetic binary image with several rounded blob-like objects.
Parameters
----------
length : int, default 512
length : int, optional
Linear size of output image.
blob_size_fraction : float, default 0.1
blob_size_fraction : float, optional
Typical linear size of blob, as a fraction of ``length``, should be
smaller than 1.
n_dim : int, default 2
n_dim : int, optional
Number of dimensions of output image.
volume_fraction : float, default 0.5
Fraction of image pixels covered by the blobs (where the output is 1).
Should be in [0, 1].
seed : int, default 0
seed : int, optional
Seed to initialize the random number generator.
Returns
@@ -29,15 +29,18 @@ def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2,
Examples
--------
>>> data.binary_blobs(length=5, blob_size_fraction=0.2, seed=1)
array([[ True, False, True, True, True],
[ True, True, True, False, True],
[False, True, False, True, True],
[ True, False, False, True, True],
[ True, False, False, False, True]], dtype=bool)
>>> blobs = binary_blobs(length=256, blob_size_fraction=0.1)
>>> # Finer structures
>>> blobs = binary_blobs(length=256, blob_size_fraction=0.05)
>>> # Blobs cover a smaller volume fraction of the image
>>> blobs = binary_blobs(length=256, volume_fraction=0.3)
"""
if seed is None:
seed = 0
# Fix the seed for reproducible results
rs = np.random.RandomState(seed)
shape = tuple([length] * n_dim)
mask = np.zeros(shape)
+6
View File
@@ -1,3 +1,4 @@
import numpy as np
import skimage.data as data
from numpy.testing import assert_equal
@@ -7,6 +8,7 @@ def test_lena():
lena = data.lena()
assert_equal(lena.shape, (512, 512, 3))
def test_astronaut():
""" Test that "astronaut" image can be loaded. """
astronaut = data.astronaut()
@@ -61,6 +63,10 @@ def test_binary_blobs():
assert blobs.mean() == 0.25
blobs = data.binary_blobs(length=32, volume_fraction=0.25, n_dim=3)
assert blobs.mean() == 0.25
other_realization = data.binary_blobs(length=32, volume_fraction=0.25,
n_dim=3)
assert not np.all(blobs == other_realization)
if __name__ == "__main__":
from numpy.testing import run_module_suite