Merge pull request #598 from sciunto/fix_import

Fix import + pep8
This commit is contained in:
Johannes Schönberger
2013-06-21 12:45:51 -07:00
14 changed files with 110 additions and 94 deletions
+19 -14
View File
@@ -14,23 +14,27 @@ Authors
import os.path
import numpy as np
from numpy.testing import *
from numpy.testing import (assert_equal,
assert_almost_equal,
assert_array_almost_equal,
assert_raises,
TestCase,
)
from skimage import img_as_float, img_as_ubyte
from skimage.io import imread
from skimage.color import (
rgb2hsv, hsv2rgb,
rgb2xyz, xyz2rgb,
rgb2hed, hed2rgb,
separate_stains,
combine_stains,
rgb2rgbcie, rgbcie2rgb,
convert_colorspace,
rgb2grey, gray2rgb,
xyz2lab, lab2xyz,
lab2rgb, rgb2lab,
is_rgb, is_gray
)
from skimage.color import (rgb2hsv, hsv2rgb,
rgb2xyz, xyz2rgb,
rgb2hed, hed2rgb,
separate_stains,
combine_stains,
rgb2rgbcie, rgbcie2rgb,
convert_colorspace,
rgb2grey, gray2rgb,
xyz2lab, lab2xyz,
lab2rgb, rgb2lab,
is_rgb, is_gray
)
from skimage import data_dir, data
@@ -267,4 +271,5 @@ def test_is_rgb():
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()
+9 -1
View File
@@ -4,7 +4,10 @@ from skimage import data
from skimage import feature
from skimage import img_as_float
from skimage import draw
from numpy.testing import *
from numpy.testing import (assert_raises,
assert_almost_equal,
)
def test_histogram_of_oriented_gradients():
img = img_as_float(data.lena()[:256, :].mean(axis=2))
@@ -14,16 +17,19 @@ def test_histogram_of_oriented_gradients():
assert len(fd) == 9 * (256 // 8) * (512 // 8)
def test_hog_image_size_cell_size_mismatch():
image = data.camera()[:150, :200]
fd = feature.hog(image, orientations=9, pixels_per_cell=(8, 8),
cells_per_block=(1, 1))
assert len(fd) == 9 * (150 // 8) * (200 // 8)
def test_hog_color_image_unsupported_error():
image = np.zeros((20, 20, 3))
assert_raises(ValueError, feature.hog, image)
def test_hog_basic_orientations_and_data_types():
# scenario:
# 1) create image (with float values) where upper half is filled by zeros, bottom half by 100
@@ -90,6 +96,7 @@ def test_hog_basic_orientations_and_data_types():
assert_almost_equal(actual, desired, decimal=2)
def test_hog_orientations_circle():
# scenario:
# 1) create image with blurred circle in the middle
@@ -129,6 +136,7 @@ def test_hog_orientations_circle():
desired = np.mean(hog_matrix)
assert_almost_equal(actual, desired, decimal=1)
if __name__ == '__main__':
from numpy.testing import run_module_suite
run_module_suite()
+1 -2
View File
@@ -1,5 +1,3 @@
from numpy.testing import *
import time
import random
import skimage.graph.heap as heap
@@ -49,4 +47,5 @@ def _test_heap(n, fast_update):
return t1 - t0
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()
+3 -10
View File
@@ -1,5 +1,7 @@
import numpy as np
from numpy.testing import *
from numpy.testing import (assert_array_equal,
assert_almost_equal,
)
import skimage.graph.mcp as mcp
@@ -7,15 +9,6 @@ a = np.ones((8, 8), dtype=np.float32)
a[1:-1, 1] = 0
a[1, 1:-1] = 0
## array([[ 1., 1., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 0., 0., 0., 0., 0., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=float32)
def test_basic():
m = mcp.MCP(a, fully_connected=True)
+5 -1
View File
@@ -2,7 +2,10 @@ import sys
import os.path
import numpy as np
from numpy.testing import *
from numpy.testing import (assert_raises,
assert_equal,
assert_array_almost_equal,
)
from numpy.testing.decorators import skipif
from skimage import data_dir
@@ -148,4 +151,5 @@ class TestMultiImage():
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()
+6 -1
View File
@@ -1,4 +1,8 @@
from numpy.testing import *
from numpy.testing import (assert_array_equal,
assert_almost_equal,
assert_equal,
assert_array_almost_equal,
)
import numpy as np
import skimage.io._plugins._colormixer as cm
@@ -136,4 +140,5 @@ class TestColorMixer(object):
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()
-1
View File
@@ -55,7 +55,6 @@ def test_imread_palette():
@skipif(not PIL_available)
def test_palette_is_gray():
from PIL import Image
gray = Image.open(os.path.join(data_dir, 'palette_gray.png'))
assert _palette_is_grayscale(gray)
color = Image.open(os.path.join(data_dir, 'palette_color.png'))
+1 -1
View File
@@ -1,6 +1,5 @@
import os.path
import numpy as np
from numpy.testing import *
from numpy.testing.decorators import skipif
from tempfile import NamedTemporaryFile
@@ -90,4 +89,5 @@ class TestSave:
yield self.roundtrip, dtype, x
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()
+3 -10
View File
@@ -1,5 +1,7 @@
import numpy as np
from numpy.testing import *
from numpy.testing import (assert_raises,
assert_array_equal,
)
from skimage.measure import find_contours
@@ -7,15 +9,6 @@ a = np.ones((8, 8), dtype=np.float32)
a[1:-1, 1] = 0
a[1, 1:-1] = 0
## array([[ 1., 1., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 0., 0., 0., 0., 0., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
## [ 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=float32)
x, y = np.mgrid[-1:1:5j, -1:1:5j]
r = np.sqrt(x**2 + y**2)
+12 -8
View File
@@ -84,14 +84,18 @@ def skeletonize(image):
# look up table - there is one entry for each of the 2^8=256 possible
# combinations of 8 binary neighbours. 1's, 2's and 3's are candidates
# for removal at each iteration of the algorithm.
lut = [0,0,0,1,0,0,1,3,0,0,3,1,1,0,1,3,0,0,0,0,0,0,0,0,2,0,2,0,3,0,3,3,
0,0,0,0,0,0,0,0,3,0,0,0,0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 0,
1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3,
0, 1, 0, 0, 0, 0, 2, 2, 0, 0, 2, 0, 0, 0]
# convert to unsigned int (this should work for boolean values)
skeleton = image.astype(np.uint8)
+42 -42
View File
@@ -296,27 +296,27 @@ class TestWatershed(unittest.TestCase):
def test_watershed07(self):
"A regression test of a competitive case that failed"
data = np.array([[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255],
[255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255],
[255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255],
[255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255],
[255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255],
[255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255],
[255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255],
[255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255],
[255,255,255,255,255,204,153,103,103,153,204,255,255,255,255,255],
[255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255],
[255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255],
[255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255],
[255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255],
[255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255],
[255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255],
[255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255],
[255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]])
data = np.array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255],
[255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255],
[255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255],
[255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255],
[255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255],
[255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255],
[255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 153, 103, 103, 153, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255],
[255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255],
[255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255],
[255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255],
[255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255],
[255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255],
[255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]])
mask = (data != 255)
markers = np.zeros(data.shape, int)
markers[6, 7] = 1
@@ -332,27 +332,27 @@ class TestWatershed(unittest.TestCase):
def test_watershed08(self):
"The border pixels + an edge are all the same value"
data = np.array([[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255],
[255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255],
[255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255],
[255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255],
[255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255],
[255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255],
[255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255],
[255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255],
[255,255,255,255,255,204,153,141,141,153,204,255,255,255,255,255],
[255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255],
[255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255],
[255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255],
[255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255],
[255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255],
[255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255],
[255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255],
[255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]])
data = np.array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255],
[255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255],
[255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255],
[255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255],
[255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255],
[255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255],
[255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 153, 141, 141, 153, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255],
[255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255],
[255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255],
[255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255],
[255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255],
[255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255],
[255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255],
[255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]])
mask = (data != 255)
markers = np.zeros(data.shape, int)
markers[6, 7] = 1
@@ -1,7 +1,6 @@
import numpy as np
from numpy.testing import *
from skimage.transform import *
from skimage.transform import frt2, ifrt2
def test_frt():
@@ -17,3 +16,8 @@ def test_frt():
f = frt2(L)
fi = ifrt2(f)
assert len(np.nonzero(L - fi)[0]) == 0
if __name__ == '__main__':
from numpy.testing import run_module_suite
run_module_suite()
+2 -1
View File
@@ -1,5 +1,5 @@
import numpy as np
from numpy.testing import *
from numpy.testing import assert_equal
from skimage.transform import integral_image, integrate
@@ -43,4 +43,5 @@ def test_vectorized_integrate():
if __name__ == '__main__':
from numpy.testing import run_module_suite
run_module_suite()
@@ -181,4 +181,5 @@ def test_radon_iradon_circle():
if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()