ENH: Minor clean ups of data loader.

This commit is contained in:
Stefan van der Walt
2011-09-25 15:15:07 -07:00
parent 41ed86d49b
commit 8da0ea52c0
2 changed files with 48 additions and 29 deletions
+31 -13
View File
@@ -1,24 +1,42 @@
"""Convinience functions to get sample data"""
"""Convenience functions to load sample data.
import os
"""
import os as _os
from ..io import imread
from ...image import data_dir
def camera():
"""Example gray "camera" image, often used for segmentation
and denoising examples."""
def load(f):
"""Load an image file located in the data directory.
return imread(os.path.join(data_dir, "camera.png"))
Parameters
----------
f : string
File name.
Returns
-------
img : ndarray
Image loaded from scikits.image.data_dir.
"""
return imread(_os.path.join(data_dir, f))
def camera():
"""Gray "camera" image, often used for segmentation
and denoising examples.
"""
return load("camera.png")
def lena():
"""Example "Lena" image. """
return imread(os.path.join(data_dir, "lena.png"))
"""Colour "Lena" image.
"""
return load("lena.png")
def checkerboard():
"""Checkerboard image"""
return imread(os.path.join(data_dir, "chessboard_RGB.png"))
"""Checkerboard image.
def checkerboard_gray():
"""Checkerboard image, only gray channel"""
return imread(os.path.join(data_dir, "chessboard_GRAY.png"))
"""
return load("chessboard_RGB.png")
+17 -16
View File
@@ -1,22 +1,23 @@
import unittest
import scikits.image.data as data
from numpy.testing import assert_equal, assert_array_equal
import numpy as np
class TestData(unittest.TestCase):
def test_lena(self):
""" Test that "Lena" image can be loaded. """
data.lena()
def test_lena():
""" Test that "Lena" image can be loaded. """
lena = data.lena()
assert_equal(lena.shape, (512, 512, 3))
def test_camera(self):
""" Test that "camera" image can be loaded. """
data.camera()
def test_camera():
""" Test that "camera" image can be loaded. """
cameraman = data.camera()
assert_equal(cameraman.ndim, 2)
def test_checkerboard(self):
""" Test that checkerboard image can be loaded. """
data.checkerboard()
def test_checkerboard_gray(self):
""" Test that checkerboard grayscale image can be loaded. """
data.checkerboard_gray()
def test_checkerboard():
""" Test that checkerboard image can be loaded. """
checkerboard = data.checkerboard()
assert_equal(checkerboard.dtype, np.uint8)
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()