Clean up PIL plugin and handle more warnings

Use the pil plugin to load data files

Fix install_requires string formatting

Dead end commit

Make all tools executable

Remove debug print

Suppress PIL resourcewarnings

Handle a few more warnings
This commit is contained in:
Steven Silvester
2014-12-23 16:48:38 -06:00
parent 79c648b14c
commit 2756358f3c
14 changed files with 25 additions and 13 deletions
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
View File
Executable → Regular
+1 -1
View File
@@ -149,7 +149,7 @@ if __name__ == "__main__":
configuration=configuration,
install_requires=[
"six>=%s" % DEPENDENCIES['six']
"six>=%s" % '.'.join(str(d) for d in DEPENDENCIES['six'])
],
packages=setuptools.find_packages(exclude=['doc']),
include_package_data=True,
+2 -1
View File
@@ -8,7 +8,7 @@ For more images, see
import os as _os
from ..io import imread
from ..io import imread, use_plugin
from skimage import data_dir
@@ -42,6 +42,7 @@ def load(f):
img : ndarray
Image loaded from skimage.data_dir.
"""
use_plugin('pil')
return imread(_os.path.join(data_dir, f))
+3 -2
View File
@@ -7,6 +7,7 @@ from PIL import Image
from skimage.util import img_as_ubyte, img_as_uint
from skimage.external.tifffile import (
imread as tif_imread, imsave as tif_imsave)
from skimage._shared.utils import all_warnings
def imread(fname, dtype=None, img_num=None, **kwargs):
@@ -39,7 +40,6 @@ def imread(fname, dtype=None, img_num=None, **kwargs):
.. [2] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
"""
print('imread', fname)
if hasattr(fname, 'lower') and dtype is None:
kwargs.setdefault('key', img_num)
if fname.lower().endswith(('.tiff', '.tif')):
@@ -54,7 +54,8 @@ def imread(fname, dtype=None, img_num=None, **kwargs):
site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries"
raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site))
else:
return pil_to_ndarray(im, dtype=dtype, img_num=img_num)
with all_warnings(): # PIL resource warnings
return pil_to_ndarray(im, dtype=dtype, img_num=img_num)
def pil_to_ndarray(im, dtype=None, img_num=None):
Executable → Regular
View File
View File
+4 -2
View File
@@ -3,6 +3,7 @@ from numpy.testing import assert_equal, assert_raises, assert_almost_equal
from skimage.measure import LineModel, CircleModel, EllipseModel, ransac
from skimage.transform import AffineTransform
from skimage.measure.fit import _dynamic_max_trials
from skimage._shared.utils import all_warnings
def test_line_model_invalid_input():
@@ -180,7 +181,7 @@ def test_ransac_geometric():
model_est, inliers = ransac((src, dst), AffineTransform, 2, 20)
# test whether estimated parameters equal original parameters
assert_almost_equal(model0._matrix, model_est._matrix)
assert_almost_equal(model0.params, model_est.params)
assert np.all(np.nonzero(inliers == False)[0] == outliers)
@@ -255,7 +256,8 @@ def test_deprecated_params_attribute():
model.params = (10, 1)
x = np.arange(-10, 10)
y = model.predict_y(x)
assert_equal(model.params, model._params)
with all_warnings(): # deprecation
assert_equal(model.params, model._params)
if __name__ == "__main__":
+10 -5
View File
@@ -4,6 +4,7 @@ import numpy as np
import math
from skimage.measure._regionprops import regionprops, PROPS, perimeter
from skimage._shared.utils import all_warnings
SAMPLE = np.array(
@@ -25,7 +26,8 @@ INTENSITY_SAMPLE[1, 9:11] = 2
def test_all_props():
region = regionprops(SAMPLE, INTENSITY_SAMPLE)[0]
for prop in PROPS:
assert_equal(region[prop], getattr(region, PROPS[prop]))
with all_warnings(): # deprecation warning
assert_equal(region[prop], getattr(region, PROPS[prop]))
def test_dtype():
@@ -125,12 +127,14 @@ def test_equiv_diameter():
def test_euler_number():
en = regionprops(SAMPLE)[0].euler_number
with all_warnings(): # deprecation warning
en = regionprops(SAMPLE)[0].euler_number
assert en == 0
SAMPLE_mod = SAMPLE.copy()
SAMPLE_mod[7, -3] = 0
en = regionprops(SAMPLE_mod)[0].euler_number
with all_warnings(): # deprecation warning
en = regionprops(SAMPLE_mod)[0].euler_number
assert en == -1
@@ -369,8 +373,9 @@ def test_equals():
r2 = regions[0]
r3 = regions[1]
assert_equal(r1 == r2, True, "Same regionprops are not equal")
assert_equal(r1 != r3, True, "Different regionprops are equal")
with all_warnings(): # deprecation warning
assert_equal(r1 == r2, True, "Same regionprops are not equal")
assert_equal(r1 != r3, True, "Different regionprops are equal")
if __name__ == "__main__":
Executable → Regular
View File
+5 -2
View File
@@ -10,6 +10,7 @@ from skimage.transform import (warp, warp_coords, rotate, resize, rescale,
downscale_local_mean)
from skimage import transform as tf, data, img_as_float
from skimage.color import rgb2gray
from skimage._shared.utils import all_warnings
np.random.seed(0)
@@ -196,8 +197,10 @@ def test_swirl():
image = img_as_float(data.checkerboard())
swirl_params = {'radius': 80, 'rotation': 0, 'order': 2, 'mode': 'reflect'}
swirled = tf.swirl(image, strength=10, **swirl_params)
unswirled = tf.swirl(swirled, strength=-10, **swirl_params)
with all_warnings(): # deprecation warning
swirled = tf.swirl(image, strength=10, **swirl_params)
unswirled = tf.swirl(swirled, strength=-10, **swirl_params)
assert np.mean(np.abs(image - unswirled)) < 0.01