Update Travis build to use Anaconda.

Update Travis build to use Anaconda

Travis updates and fixes

More travis fixes

Another travis attempt

Revert changes

Use PIL and Pillow

Refactor travis into 4 different builds

Fix activation error

Remove explicit mpl in build_versions.py

Make matplotlib an explicit requirement

Rearrange travis

Make pillow a hard requirement

Try again to make Pillow optional

Fix bash syntax error

Fix bash syntax error

Bump required cython version

More rearrangments

Remove mpl from build_versions, rearrange travis

Fix version check

Make matplotlib explicit again

Conda install into test env

Check for proper install

Allow tests to skip if networkx is not available

Allow tests to skip if networkx is not available

Try swapping pillow for matplotlib

Allow tests to pass when matplotlib is not present

Remove matplotlib from build_versions

Print PIL version

Get pillow from PIP

Allow tests to skip if matplotlib is not present.

Allow tests to skip if networkx is not present.

travis fix

Remove unused mpl import that caused test error

Use nose-cov and do not run doctests without optional libs

Bump required numpy version and fix nose calls

Make overlay test repeatable

bump numpy version again

Move low-end numpy to python 2.7

Play with minimum versions

Add version requirements and use functions

Add version requirements and use functions

Allow require to skip a test

More implementation of require decorator

Update require decorator and clean up tests

Only use requires decorator when needed

Fix python3 error in version_requirements

Fix build errors

Fix handling of require with tests

More fixes for require handler

Use latest miniconda

Fix more build errors

Fix another dict comprehension and travis file.

Fix missing imports

Fix dictionary again

Fix import warning

Fix last failing test on 2.6

Skip doc examples on python2.6

Do not run doctests on python2.6

Fix typo in travis.yml

Make numpy-1.6 compatibility changes

Use numpy-1.6 in travis python2.6

Add tests for version requirements

Fix line noise in PR

Add additional io plugins

Fix simpleitk test.

Fix python 3 error in freeimage_plugin.

Install imread in Travis.

Put matplotlib settings in XDG recommended directory

Fix formatting in travis yml

Fix formatting in travis yml

Make sure to close PIL file atexit

Fix name of apt package xcftools

Fix pil fp closing

Fix matplotlibrc creation

Only download SimpleITK on py2x, run coverage on py27

Fix travis yml syntax error

Run coveralls on py2.7

Install SimpleITK on py3.3 and run coverage on py3.3

Make simpleitk install quiet

Use standard nose and clean up incantation

Fix travis yml syntax error

Put in miniconda workout for libc error.

Fix imread plugin.

Fix travis syntax

Remove unused import

Remove miniconda libpng in favor of system png

Fix imread install and move libm removal to after optional pkg install.

Fix png header copy in travis yml

Another attempt to use png headers

Debug freeimage

Add jpeg library for freeimage and debug imread.

More debug for imread and freeimage

More freeimage and imread debugging

More debugging

Use correct paths for test env

Make sure imread is tied to libpng15

Add a TODO note for simpleitk test causing error.

Fix typo in yml

Cleanup and add more comments to travis yml

Update comment

Try and add 3.2 support.

Docstring formatting

Add more travis comments.

Try numpy 1.6 on python 2.7

Fix travis syntax error

Rename CONDA to ENV for clarity

Alias python on python 3.2

Use python 3.2 as the system python

Clean up libfreeimage install

Fix order on py3.2 pre_install

Move old numpy back to py26

Use the appropriate python calls.

Debug 3.2 build.

Update comment

Fix syntax error

Another fix for syntax error.

Install scipy after downloading import tools

More debugging for py32

Do not install conda on py3.2 (duh)

Fix typo in travis yml

Fix py32 qt install, separate pyfits and imread to find error

Fix syntax error and front-load option lib check for debug

pyfits is not supported in py3.2, try imread now

imread is also not supported on py3.2

install imread before pyfits to show relationship with libs

Make pip builds quiet

Minor formatting to retrigger build

Allow simpleitk to fail to download without breaking the build

Use travis_retry for SimpleITK

See what breaks when we keep libm in

Now remove libm again
This commit is contained in:
blink1073
2014-08-02 06:47:09 -05:00
committed by Steven Silvester
parent 85a5cea533
commit b6dcf3c336
33 changed files with 380 additions and 172 deletions
+81 -64
View File
@@ -3,28 +3,17 @@
# After changing this file, check it on:
# http://lint.travis-ci.org/
language: python
python:
- 2.6
- 3.2
matrix:
include:
- python: 2.7
env:
- PYTHON=python
- PYTHONWARNINGS=all
- PYTHONX=python
- PYVER=2.x
- python: 3.2
env:
- PYTHON=python3
- PYTHONWARNINGS=all
- PYTHONX=python3
- PYVER=3.x
exclude:
- python: 2.6
env:
- ENV="python=2.6 numpy=1.6 cython=0.19.2"
- ENV="python=2.7 numpy cython"
- ENV="python=3.2"
- ENV="python=3.3 numpy cython"
- ENV="python=3.4 numpy cython"
virtualenv:
system_site_packages: true
@@ -32,64 +21,92 @@ virtualenv:
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo apt-get update
- sudo apt-get install $PYTHON-numpy
- wget https://raw.githubusercontent.com/numpy/numpy/master/numpy/_import_tools.py -O /home/travis/virtualenv/python3.2_with_system_site_packages/lib/python3.2/site-packages/numpy/_import_tools.py
- sudo apt-get install $PYTHON-scipy
- sudo apt-get install libfreeimage3
- if [[ $PYVER == '2.x' ]]; then
- sudo apt-get install $PYTHON-qt4;
- sudo apt-get install $PYTHON-matplotlib;
- fi
- if [[ $PYVER == '3.x' ]]; then
- sudo apt-get install $PYTHON-pyqt4;
- pip install --use-mirrors matplotlib;
- fi
- pip install pillow
- pip install cython
- pip install flake8
- pip install six
- pip install networkx
- pip install nose-cov
- pip install coveralls
- if [[ $ENV == python=3.2 ]]; then
sudo apt-get install python3-numpy;
wget https://raw.githubusercontent.com/numpy/numpy/master/numpy/_import_tools.py -O /home/travis/virtualenv/python3.2_with_system_site_packages/lib/python3.2/site-packages/numpy/_import_tools.py;
sudo apt-get install python3-scipy;
pip install cython flake8 six;
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
hash -r;
conda config --set always_yes yes;
conda update conda;
conda info -a;
conda create -n test $ENV six scipy pip flake8 nose;
source activate test;
fi
- pip install coveralls pillow
- python check_bento_build.py
install:
- tools/header.py "Dependency versions"
- tools/build_versions.py
- export PYTHONWARNINGS=all
- python setup.py build_ext --inplace
script:
# Matplotlib settings
- mkdir -p $HOME/.matplotlib
- touch $HOME/.matplotlib/matplotlibrc
- "echo 'backend : Agg' > $HOME/.matplotlib/matplotlibrc"
- "echo 'backend.qt4 : PyQt4' >> $HOME/.matplotlib/matplotlibrc"
# Run all tests
- if [[ $PYVER == '3.x' ]]; then
- nosetests --exe -v --with-doctest --with-cov --cov skimage --cov-config=.coveragerc skimage
- fi
- if [[ $PYVER == '2.x' ]]; then
- nosetests --exe -v --with-doctest skimage
- fi
# Run all doc examples
- export PYTHONPATH=$(pwd):$PYTHONPATH
- for f in doc/examples/*.py; do $PYTHONX "$f"; if [ $? -ne 0 ]; then exit 1; fi done
- for f in doc/examples/applications/*.py; do $PYTHONX "$f"; if [ $? -ne 0 ]; then exit 1; fi done
# Run all tests with minimum dependencies
- nosetests --exe -v skimage
# Run pep8 and flake tests
- flake8 --exit-zero --exclude=test_*,six.py skimage doc/examples viewer_examples
# Install optional dependencies to get full test coverage
# Notes:
# - pyfits and imread do NOT support py3.2
# - Use the png headers included in anaconda (from matplotlib install)
# TODO: Remove the libm removal when anaconda fixes their libraries
# The solution was suggested here
# https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/-DLG2ZdTkw0
- if [[ $ENV == python=3.2 ]]; then
sudo apt-get install -qq python3-pyqt4;
pip install --use-mirrors -q matplotlib;
pip install -q networkx;
else
conda install -q matplotlib pyqt networkx;
sudo cp ~/miniconda/envs/test/include/png* /usr/include;
rm ~/miniconda/envs/test/lib/libm-2.5.so;
rm ~/miniconda/envs/test/lib/libm.*;
sudo apt-get install -qq libtiff4-dev libwebp-dev xcftools;
pip install -q imread;
pip install -q pyfits;
fi
- sudo apt-get install -qq libfreeimage3
# TODO: update when SimpleITK become available on py34 or hopefully pip
- if [[ $ENV != python=3.4* ]]; then
travis_retry easy_install -q SimpleITK;
fi
# Matplotlib settings
- export MPL_DIR=$HOME/.config/matplotlib
- mkdir -p $MPL_DIR
- touch $MPL_DIR/matplotlibrc
- "echo 'backend : Agg' > $MPL_DIR/matplotlibrc"
- "echo 'backend.qt4 : PyQt4' >> $MPL_DIR/matplotlibrc"
# Run all doc examples
- export PYTHONPATH=$(pwd):$PYTHONPATH
- if [[ $ENV != python=2.6* ]]; then
for f in doc/examples/*.py; do python "$f"; if [ $? -ne 0 ]; then exit 1; fi done
fi
- for f in doc/examples/applications/*.py; do python "$f"; if [ $? -ne 0 ]; then exit 1; fi done
# run tests again with optional dependencies to get more coverage
# measure coverage on py3.3
# doctests fail on python 2.6 for restoration/unwrap
- if [[ $ENV == python=3.3* ]]; then
nosetests --exe -v --with-doctest --with-cov --cover-package skimage;
elif [[ $ENV == python=2.6* ]]; then
nosetests --exe -v skimage;
else
nosetests --exe -v --with-doctest skimage;
fi
after_success:
- if [[ $PYVER == '3.x' ]]; then
- coveralls
- fi
- if [[ $ENV == python=3.3* ]]; then
coveralls;
fi
+2 -2
View File
@@ -17,7 +17,7 @@ import numpy as np
import skimage
from skimage.color.adapt_rgb import adapt_rgb, hsv_value
from skimage.exposure import rescale_intensity
from skimage.util import view_as_blocks
from skimage.util import view_as_blocks, pad
MAX_REG_X = 16 # max. # contextual regions in x-direction */
@@ -125,7 +125,7 @@ def _clahe(image, ntiles_x, ntiles_y, clip_limit, nbins=128):
if h_inner != image.shape[1] or w_inner != image.shape[0]:
h_pad = height * ntiles_y - image.shape[0]
w_pad = width * ntiles_x - image.shape[1]
image = np.pad(image, ((0, h_pad), (0, w_pad)), 'reflect')
image = pad(image, ((0, h_pad), (0, w_pad)), mode='reflect')
h_inner, w_inner = image.shape
bin_size = 1 + NR_OF_GREY / nbins
+5 -1
View File
@@ -1,5 +1,8 @@
import numpy as np
import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ImportError:
plt = None
from numpy.testing import assert_equal, assert_raises
from skimage.feature.util import (FeatureDetector, DescriptorExtractor,
@@ -39,6 +42,7 @@ def test_mask_border_keypoints():
[0, 0, 0, 0, 1])
@np.testing.decorators.skipif(plt is None)
def test_plot_matches():
fig, ax = plt.subplots(nrows=1, ncols=1)
+6 -1
View File
@@ -1,4 +1,9 @@
import networkx as nx
try:
import networkx as nx
except ImportError:
import warnings
warnings.warn('"cut_threshold" requires networkx')
nx = None
import numpy as np
+8 -1
View File
@@ -1,4 +1,11 @@
import networkx as nx
try:
import networkx as nx
except ImportError:
class nx:
class Graph:
pass
import warnings
warnings.warn('Region Adjacency Graph (RAG) features require networkx')
import numpy as np
from scipy.ndimage import filters
from scipy import ndimage as nd
+3
View File
@@ -1,5 +1,6 @@
import numpy as np
from skimage import graph
from skimage.util.version_requirements import require
def max_edge(g, src, dst, n):
@@ -9,6 +10,7 @@ def max_edge(g, src, dst, n):
return max(w1, w2)
@require('networkx')
def test_rag_merge():
g = graph.rag.RAG()
@@ -43,6 +45,7 @@ def test_rag_merge():
assert g.edges() == []
@require('networkx')
def test_threshold_cut():
img = np.zeros((100, 100, 3), dtype='uint8')
+1 -1
View File
@@ -85,7 +85,7 @@ def load_freeimage():
if errors:
# No freeimage library loaded, and load-errors reported for some
# candidate libs
err_txt = ['%s:\n%s' % (l, str(e.message)) for l, e in errors]
err_txt = ['%s:\n%s' % (l, str(e)) for l, e in errors]
raise RuntimeError('One or more FreeImage libraries were found, but '
'could not be loaded due to the following errors:\n'
'\n\n'.join(err_txt))
+1 -1
View File
@@ -1,6 +1,6 @@
__all__ = ['imread', 'imsave']
from skimage.utils.dtype import convert
from skimage.util.dtype import convert
try:
import imread as _imread
+4 -2
View File
@@ -21,6 +21,7 @@ def imread(fname, dtype=None):
"""
im = Image.open(fname)
fp = im.fp
if im.mode == 'P':
if _palette_is_grayscale(im):
im = im.convert('L')
@@ -35,8 +36,9 @@ def imread(fname, dtype=None):
im.shape = shape[::-1]
elif 'A' in im.mode:
im = im.convert('RGBA')
return np.array(im, dtype=dtype)
im = np.array(im, dtype=dtype)
fp.close()
return im
def _palette_is_grayscale(pil_image):
+1 -1
View File
@@ -158,7 +158,7 @@ def imsave(filename, img, format_str=None):
qbuffer.open(QtCore.QIODevice.ReadWrite)
saved = qimg.save(qbuffer, format_str.upper())
qbuffer.seek(0)
filename.write(qbuffer.readAll())
filename.write(qbuffer.readAll().data())
qbuffer.close()
else:
saved = qimg.save(filename)
+4 -1
View File
@@ -7,6 +7,7 @@ from tempfile import NamedTemporaryFile
from skimage import data_dir
from skimage.io import imread, imsave, use_plugin, reset_plugins
import skimage.io as sio
try:
import imread as _imread
@@ -39,11 +40,13 @@ def test_imread_palette():
img = imread(os.path.join(data_dir, 'palette_color.png'))
assert img.ndim == 3
@skipif(not imread_available)
def test_imread_truncated_jpg():
assert_raises((RuntimeError, ValueError),
sio.imread,
os.path.join(si.data_dir, 'truncated.jpg'))
os.path.join(data_dir, 'truncated.jpg'))
@skipif(not imread_available)
def test_bilevel():
+7 -3
View File
@@ -1,6 +1,7 @@
import os.path
import numpy as np
from numpy.testing.decorators import skipif
from numpy.testing import assert_raises
from tempfile import NamedTemporaryFile
@@ -52,12 +53,15 @@ def test_bilevel():
img = imread(os.path.join(data_dir, 'checker_bilevel.png'))
np.testing.assert_array_equal(img, expected)
"""
#TODO: This test causes a Segmentation fault
@skipif(not sitk_available)
def test_imread_truncated_jpg():
assert_raises((RuntimeError, ValueError),
sio.imread,
os.path.join(si.data_dir, 'truncated.jpg'))
imread,
os.path.join(data_dir, 'truncated.jpg'))
"""
@skipif(not sitk_available)
def test_imread_uint16():
+1 -1
View File
@@ -131,7 +131,7 @@ def reconstruction(seed, mask, method='dilation', selem=None, offset=None):
if selem is None:
selem = np.ones([3] * seed.ndim, dtype=bool)
else:
selem = selem.astype(bool, copy=True)
selem = selem.astype(bool)
if offset is None:
if not all([d % 2 == 1 for d in selem.shape]):
+3 -2
View File
@@ -5,12 +5,13 @@ from .selem import _default_selem
# Our function names don't exactly correspond to ndimages.
# This dictionary translates from our names to scipy's.
funcs = ('erosion', 'dilation', 'opening', 'closing')
skimage2ndimage = {x: 'grey_' + x for x in funcs}
skimage2ndimage = dict((x, 'grey_' + x) for x in funcs)
# These function names are the same in ndimage.
funcs = ('binary_erosion', 'binary_dilation', 'binary_opening',
'binary_closing', 'black_tophat', 'white_tophat')
skimage2ndimage.update({x: x for x in funcs})
skimage2ndimage.update(dict((x, x) for x in funcs))
def default_fallback(func):
"""Decorator to fall back on ndimage for images with more than 2 dimensions
+7
View File
@@ -7,6 +7,7 @@ from numpy.testing import (run_module_suite, assert_array_almost_equal,
import warnings
from skimage.restoration import unwrap_phase
from skimage.util.version_requirements import require
def assert_phase_almost_equal(a, b, *args, **kwargs):
@@ -41,6 +42,7 @@ def check_unwrap(image, mask=None):
assert_phase_almost_equal(image_unwrapped, image)
@require('python', '>=2.7')
def test_unwrap_1d():
image = np.linspace(0, 10 * np.pi, 100)
check_unwrap(image)
@@ -50,6 +52,7 @@ def test_unwrap_1d():
assert_raises(ValueError, unwrap_phase, image, True)
@require('python', '>=2.7')
def test_unwrap_2d():
x, y = np.ogrid[:8, :16]
image = 2 * np.pi * (x * 0.2 + y * 0.1)
@@ -59,6 +62,7 @@ def test_unwrap_2d():
yield check_unwrap, image, mask
@require('python', '>=2.7')
def test_unwrap_3d():
x, y, z = np.ogrid[:8, :12, :16]
image = 2 * np.pi * (x * 0.2 + y * 0.1 + z * 0.05)
@@ -104,12 +108,14 @@ def check_wrap_around(ndim, axis):
image_unwrap_wrap_around[index_last])
@require('python', '>=2.7')
def test_wrap_around():
for ndim in (2, 3):
for axis in range(ndim):
yield check_wrap_around, ndim, axis
@require('python', '>=2.7')
def test_mask():
length = 100
ramps = [np.linspace(0, 4 * np.pi, length),
@@ -137,6 +143,7 @@ def test_mask():
assert_array_almost_equal(image_unwrapped_3d[:, :, -1], image[i, -1])
@require('python', '>=2.7')
def test_invalid_input():
assert_raises(ValueError, unwrap_phase, np.zeros([]))
assert_raises(ValueError, unwrap_phase, np.zeros((1, 1, 1, 1)))
+2
View File
@@ -1,12 +1,14 @@
import numpy as np
import warnings
from six import string_types
from skimage.util.version_requirements import require
from ._unwrap_1d import unwrap_1d
from ._unwrap_2d import unwrap_2d
from ._unwrap_3d import unwrap_3d
@require('python', '>=2.7')
def unwrap_phase(image, wrap_around=False):
'''From ``image``, wrapped to lie in the interval [-pi, pi), recover the
original, unwrapped image.
@@ -0,0 +1,46 @@
"""Tests for the version requirment functions.
"""
import numpy as np
from numpy.testing import assert_raises, assert_equal
import nose
from skimage.util import version_requirements as vr
def test_get_module_version():
assert vr.get_module_version('numpy')
assert vr.get_module_version('scipy')
assert_raises(ImportError, lambda: vr.get_module_version('fakenumpy'))
def test_is_installed():
assert vr.is_installed('python', '>=2.6')
assert not vr.is_installed('numpy', '<1.0')
def test_require():
@vr.require('python', '>2.6')
@vr.require('numpy', '>1.5')
def foo():
return 1
assert_equal(foo(), 1)
@vr.require('scipy', '<0.1')
def bar():
return 0
assert_raises(ImportError, lambda: bar())
@vr.require('numpy', '<1.0')
def test_this():
assert False
assert_raises(nose.SkipTest, lambda: test_this()())
def test_get_module():
assert_equal(vr.get_module('numpy'), np)
assert_equal(vr.get_module('nose'), nose)
+125
View File
@@ -0,0 +1,125 @@
from distutils.version import LooseVersion
import functools
import re
import sys
import types
from numpy.testing.decorators import skipif
def _check_version(actver, version, cmp_op):
"""
Check version string of an active module against a required version.
If dev/prerelease tags result in TypeError for string-number comparison,
it is assumed that the dependency is satisfied.
Users on dev branches are responsible for keeping their own packages up to
date.
Copyright (C) 2013 The IPython Development Team
Distributed under the terms of the BSD License.
"""
try:
if cmp_op == '>':
return LooseVersion(actver) > LooseVersion(version)
elif cmp_op == '>=':
return LooseVersion(actver) >= LooseVersion(version)
elif cmp_op == '=':
return LooseVersion(actver) == LooseVersion(version)
elif cmp_op == '<':
return LooseVersion(actver) < LooseVersion(version)
else:
return False
except TypeError:
return True
def get_module_version(module_name):
"""Return module version or None if version can't be retrieved."""
mod = __import__(module_name,
fromlist=[module_name.rpartition('.')[-1]])
return getattr(mod, '__version__', getattr(mod, 'VERSION', None))
def is_installed(name, version=None):
"""Test if *name* is installed.
Parameters
----------
name : str
Name of module or "python"
version : str, optional
Version string to test against.
If version is not None, checking version
(must have an attribute named '__version__' or 'VERSION')
Version may start with =, >=, > or < to specify the exact requirement
Note
----
Original Copyright (C) 2009-2011 Pierre Raybaut
Licensed under the terms of the MIT License.
Returns
-------
True if *name* is installed matching the optional version.
"""
if name.lower() == 'python':
actver = sys.version[:6]
else:
try:
actver = get_module_version(name)
except ImportError:
return False
if version is None:
return True
else:
match = re.search('[0-9]', version)
assert match is not None, "Invalid version number"
symb = version[:match.start()]
if not symb:
symb = '='
assert symb in ('>=', '>', '=', '<'),\
"Invalid version condition '%s'" % symb
version = version[match.start():]
return _check_version(actver, version, symb)
def require(name, version=None):
"""Return decorator that forces a requirement for a function or class.
Parameters
----------
name : str
Name of module or "python".
version : str, optional
Version string to test against.
If version is not None, checking version
(must have an attribute named '__version__' or 'VERSION')
Version may start with =, >=, > or < to specify the exact requirement
"""
def decorator(obj):
@functools.wraps(obj)
def func_wrapped(*args, **kwargs):
if is_installed(name, version):
return obj(*args, **kwargs)
else:
msg = '"%s" in "%s" requires "%s'
msg = msg % (obj, obj.__module__, name)
if not version is None:
msg += " %s" % version
raise ImportError(msg + '"')
if (isinstance(obj, types.FunctionType) and
obj.__name__.startswith('test_')):
if not is_installed(name, version):
func_wrapped = lambda: skipif(True)(obj)
else:
func_wrapped = obj
return func_wrapped
return decorator
def get_module(module_name, version=None):
if not is_installed(module_name, version):
return None
return __import__(module_name,
fromlist=[module_name.rpartition('.')[-1]])
+10
View File
@@ -1 +1,11 @@
from warnings import warn
from skimage.util.version_requirements import is_installed
from .viewers import ImageViewer, CollectionViewer
from .qt import qt_api
viewer_available = not qt_api is None and is_installed('matplotlib')
if not viewer_available:
warn('Viewer requires matplotlib and Qt')
del qt_api, is_installed, warn
+1 -3
View File
@@ -1,10 +1,8 @@
import numpy as np
try:
from matplotlib import lines
except ImportError:
print("Could not import matplotlib -- skimage.viewer not available.")
pass
__all__ = ['CanvasToolBase', 'ToolHandles']
+1 -2
View File
@@ -3,8 +3,7 @@ import numpy as np
try:
from matplotlib import lines
except ImportError:
print("Could not import matplotlib -- skimage.viewer not available.")
pass
from skimage.viewer.canvastools.base import CanvasToolBase, ToolHandles
+7 -5
View File
@@ -1,9 +1,11 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
LABELS_CMAP = mcolors.ListedColormap(['white', 'red', 'dodgerblue', 'gold',
'greenyellow', 'blueviolet'])
try:
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
LABELS_CMAP = mcolors.ListedColormap(['white', 'red', 'dodgerblue', 'gold',
'greenyellow', 'blueviolet'])
except ImportError:
pass
from skimage.viewer.canvastools.base import CanvasToolBase
-1
View File
@@ -2,7 +2,6 @@ try:
from matplotlib.widgets import RectangleSelector
except ImportError:
RectangleSelector = object
print("Could not import matplotlib -- skimage.viewer not available.")
from skimage.viewer.canvastools.base import CanvasToolBase
from skimage.viewer.canvastools.base import ToolHandles
+4 -2
View File
@@ -1,6 +1,8 @@
import numpy as np
import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ImportError:
pass
from skimage import color
from skimage import exposure
from .plotplugin import PlotPlugin
+3 -8
View File
@@ -5,17 +5,12 @@ from .base import Plugin
from ..utils import ClearColormap, update_axes_image
import six
from skimage.util.version_requirements import is_installed
__all__ = ['OverlayPlugin']
def recent_mpl_version():
import matplotlib
version = matplotlib.__version__.split('.')
return int(version[0]) == 1 and int(version[1]) >= 2
class OverlayPlugin(Plugin):
"""Plugin for ImageViewer that displays an overlay on top of main image.
@@ -38,14 +33,14 @@ class OverlayPlugin(Plugin):
'cyan': (0, 1, 1)}
def __init__(self, **kwargs):
if not recent_mpl_version():
if not is_installed('matplotlib', '>=1.2'):
msg = "Matplotlib >= 1.2 required for OverlayPlugin."
warn(RuntimeWarning(msg))
super(OverlayPlugin, self).__init__(**kwargs)
self._overlay_plot = None
self._overlay = None
self.cmap = None
self.color_names = list(self.colors.keys())
self.color_names = sorted(list(self.colors.keys()))
def attach(self, image_viewer):
super(OverlayPlugin, self).attach(image_viewer)
+7 -13
View File
@@ -4,21 +4,15 @@ import skimage
import skimage.data as data
from skimage.filter.rank import median
from skimage.morphology import disk
from skimage.viewer import ImageViewer, viewer_available
from numpy.testing import assert_equal, assert_allclose, assert_almost_equal
from numpy.testing.decorators import skipif
try:
from skimage.viewer.qt import qt_api
from skimage.viewer import ImageViewer
from skimage.viewer.plugins import (
LineProfile, Measure, CannyPlugin, LabelPainter, Crop, ColorHistogram,
PlotPlugin)
from skimage.viewer.plugins.base import Plugin
from skimage.viewer.widgets import Slider
viewer_available = not qt_api is None
except ImportError:
viewer_available = False
from skimage.viewer.plugins import (
LineProfile, Measure, CannyPlugin, LabelPainter, Crop, ColorHistogram,
PlotPlugin)
from skimage.viewer.plugins.base import Plugin
from skimage.viewer.widgets import Slider
from skimage.util.version_requirements import is_installed
def setup_line_profile(image, limits='image'):
viewer = ImageViewer(skimage.img_as_float(image))
+7 -11
View File
@@ -1,19 +1,15 @@
from collections import namedtuple
import numpy as np
from skimage import data
from numpy.testing import assert_equal
from numpy.testing.decorators import skipif
try:
from skimage.viewer.qt import qt_api
from skimage.viewer import ImageViewer
from skimage.viewer.canvastools import (
LineTool, ThickLineTool, RectangleTool, PaintTool)
from skimage.viewer.canvastools.base import CanvasToolBase
viewer_available = not qt_api is None
except ImportError:
viewer_available = False
from skimage import data
from skimage.viewer import ImageViewer, viewer_available
from skimage.viewer.canvastools import (
LineTool, ThickLineTool, RectangleTool, PaintTool)
from skimage.viewer.canvastools.base import CanvasToolBase
from numpy.testing import assert_equal
from numpy.testing.decorators import skipif
def get_end_points(image):
+10 -11
View File
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
from skimage.viewer import viewer_available
from skimage.viewer.qt import QtCore, QtGui
from skimage.viewer import utils
from skimage.viewer.utils import dialogs
from numpy.testing.decorators import skipif
try:
from skimage.viewer.qt import qt_api, QtCore, QtGui
from skimage.viewer import utils
from skimage.viewer.utils import dialogs
except ImportError:
qt_api = None
from skimage.viewer import utils
from skimage.viewer.utils import dialogs
@skipif(qt_api is None)
@skipif(not viewer_available)
def test_event_loop():
utils.init_qtapp()
timer = QtCore.QTimer()
@@ -17,7 +16,7 @@ def test_event_loop():
utils.start_qtapp()
@skipif(qt_api is None)
@skipif(not viewer_available)
def test_format_filename():
fname = dialogs._format_filename(('apple', 2))
assert fname == 'apple'
@@ -25,7 +24,7 @@ def test_format_filename():
assert fname is None
@skipif(qt_api is None)
@skipif(not viewer_available)
def test_open_file_dialog():
utils.init_qtapp()
timer = QtCore.QTimer()
@@ -34,7 +33,7 @@ def test_open_file_dialog():
assert filename is None
@skipif(qt_api is None)
@skipif(not viewer_available)
def test_save_file_dialog():
utils.init_qtapp()
timer = QtCore.QTimer()
+7 -13
View File
@@ -1,18 +1,13 @@
from skimage import data
from skimage.viewer.qt import QtGui, QtCore
from skimage.viewer import ImageViewer, CollectionViewer, viewer_available
from skimage.transform import pyramid_gaussian
from skimage.viewer.plugins import OverlayPlugin
from skimage.filter import sobel
from numpy.testing import assert_equal
from numpy.testing.decorators import skipif
try:
from skimage.viewer.qt import qt_api, QtGui, QtCore
from skimage.viewer.plugins import OverlayPlugin
from skimage.viewer.plugins.overlayplugin import recent_mpl_version
from skimage.viewer import ImageViewer, CollectionViewer
viewer_available = not qt_api is None
except ImportError:
viewer_available = False
from skimage.util.version_requirements import require
@skipif(not viewer_available)
@@ -58,7 +53,8 @@ def test_collection_viewer():
view._format_coord(10, 10)
@skipif(not viewer_available or not recent_mpl_version())
@skipif(not viewer_available)
@require('matplotlib', '>=1.2')
def test_viewer_with_overlay():
img = data.coins()
ov = OverlayPlugin(image_filter=sobel)
@@ -68,7 +64,7 @@ def test_viewer_with_overlay():
import tempfile
_, filename = tempfile.mkstemp(suffix='.png')
ov.color = 2
ov.color = 3
assert_equal(ov.color, 'yellow')
viewer.save_to_file(filename)
ov.display_filtered_image(img)
@@ -79,5 +75,3 @@ def test_viewer_with_overlay():
assert_equal(ov.overlay, img)
assert_equal(ov.filtered_image, img)
+5 -10
View File
@@ -1,19 +1,14 @@
import os
from skimage import data, img_as_float, io
from skimage.viewer import ImageViewer, viewer_available
from skimage.viewer.widgets import (
Slider, OKCancelButtons, SaveButtons, ComboBox, Text)
from skimage.viewer.plugins.base import Plugin
from skimage.viewer.qt import QtGui, QtCore
from numpy.testing import assert_almost_equal, assert_equal
from numpy.testing.decorators import skipif
try:
from skimage.viewer.qt import qt_api, QtGui, QtCore
from skimage.viewer import ImageViewer
from skimage.viewer.widgets import (
Slider, OKCancelButtons, SaveButtons, ComboBox, Text)
from skimage.viewer.plugins.base import Plugin
viewer_available = not qt_api is None
except ImportError:
viewer_available = False
def get_image_viewer():
image = data.coins()
+4 -7
View File
@@ -9,18 +9,15 @@ try:
from matplotlib.figure import Figure
from matplotlib import _pylab_helpers
from matplotlib.colors import LinearSegmentedColormap
if qt_api is None:
raise ImportError
else:
if not qt_api is None:
from matplotlib.backends.backend_qt4 import FigureManagerQT
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
if 'agg' not in mpl.get_backend().lower():
print("Recommended matplotlib backend is `Agg` for full "
"skimage.viewer functionality.")
if 'agg' not in mpl.get_backend().lower():
print("Recommended matplotlib backend is `Agg` for full "
"skimage.viewer functionality.")
except ImportError:
FigureCanvasQTAgg = object # hack to prevent nosetest and autodoc errors
LinearSegmentedColormap = object
print("Could not import matplotlib -- skimage.viewer not available.")
from ..qt import QtGui
-1
View File
@@ -123,7 +123,6 @@ class ImageViewer(QtGui.QMainWindow):
self.fig, self.ax = utils.figimage(image)
self.canvas = self.fig.canvas
self.canvas.setParent(self)
self.ax.autoscale(enable=False)
self._image_plot = self.ax.images[0]
+7 -4
View File
@@ -4,9 +4,12 @@ from __future__ import print_function
import numpy as np
import scipy as sp
import matplotlib as mpl
from PIL import Image
import six
for m in (np, sp, mpl, six):
print(m.__name__.rjust(10), ' ', m.__version__)
for m in (np, sp, Image, six):
if not m is None:
if m is Image:
print('PIL'.rjust(10), ' ', Image.VERSION)
else:
print(m.__name__.rjust(10), ' ', m.__version__)