mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 13:26:37 +08:00
Merge Neil's fixes, including those for py3k.
This commit is contained in:
@@ -95,9 +95,9 @@ def convert_colorspace(arr, fromspace, tospace):
|
||||
fromspace = fromspace.upper()
|
||||
tospace = tospace.upper()
|
||||
if not fromspace in fromdict.keys():
|
||||
raise ValueError, 'fromspace needs to be one of %s'%fromdict.keys()
|
||||
raise ValueError('fromspace needs to be one of %s'%fromdict.keys())
|
||||
if not tospace in todict.keys():
|
||||
raise ValueError, 'tospace needs to be one of %s'%todict.keys()
|
||||
raise ValueError('tospace needs to be one of %s'%todict.keys())
|
||||
|
||||
return todict[tospace](fromdict[fromspace](arr))
|
||||
|
||||
@@ -108,7 +108,7 @@ def _prepare_colorarray(arr, dtype=np.float32):
|
||||
|
||||
if arr.ndim != 3 or arr.shape[2] != 3:
|
||||
msg = "the input array must be have a shape == (.,.,3))"
|
||||
raise ValueError, msg
|
||||
raise ValueError(msg)
|
||||
|
||||
return arr.astype(dtype)
|
||||
|
||||
|
||||
@@ -11,15 +11,13 @@ except ImportError:
|
||||
"for further instructions.")
|
||||
|
||||
|
||||
def imread(fname, as_grey=True, dtype=None):
|
||||
def imread(fname, dtype=None):
|
||||
"""Load an image from a FITS file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : string
|
||||
Image file name, e.g. ``test.fits``.
|
||||
as_grey : bool
|
||||
For FITS images, this is ignored (treated as True).
|
||||
dtype : dtype, optional
|
||||
For FITS, this argument is ignored because Stefan is planning on
|
||||
removing the dtype argument from imread anyway.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ except ImportError:
|
||||
"Please refer to http://pypi.python.org/pypi/PIL/ "
|
||||
"for further instructions.")
|
||||
|
||||
def imread(fname, as_grey=False, dtype=None):
|
||||
def imread(fname, dtype=None):
|
||||
"""Load an image from file.
|
||||
|
||||
"""
|
||||
@@ -20,10 +20,6 @@ def imread(fname, as_grey=False, dtype=None):
|
||||
else:
|
||||
im = im.convert('RGB')
|
||||
|
||||
if as_grey and not \
|
||||
im.mode in ('1', 'L', 'I', 'F', 'I;16', 'I;16L', 'I;16B', 'LA'):
|
||||
im = im.convert('F')
|
||||
|
||||
if 'A' in im.mode:
|
||||
im = im.convert('RGBA')
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ def call(kind, *args, **kwargs):
|
||||
if len(plugin_funcs) == 0:
|
||||
raise RuntimeError('''No suitable plugin registered for %s.
|
||||
|
||||
You may load I/O plugins with the `scikits.image.io.load_plugin`
|
||||
You may load I/O plugins with the `scikits.image.io.use_plugin`
|
||||
command. A list of all available plugins can be found using
|
||||
`scikits.image.io.plugins()`.''' % kind)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# This mock-up is called by ../tests/test_plugin.py
|
||||
# to verify the behaviour of the plugin infrastructure
|
||||
|
||||
def imread(fname, as_grey=False, dtype=None):
|
||||
def imread(fname, dtype=None):
|
||||
assert fname == 'test.png'
|
||||
assert dtype == 'i4'
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class MultiImage(object):
|
||||
if -numframes <= n < numframes:
|
||||
n = n % numframes
|
||||
else:
|
||||
raise IndexError, "There are only %s frames in the image"%numframes
|
||||
raise IndexError("There are only %s frames in the image"%numframes)
|
||||
|
||||
if self.conserve_memory:
|
||||
if not self._cached == n:
|
||||
@@ -289,7 +289,7 @@ class ImageCollection(object):
|
||||
if -num <= n < num:
|
||||
n = n % num
|
||||
else:
|
||||
raise IndexError, "There are only %s images in the collection"%num
|
||||
raise IndexError("There are only %s images in the collection"%num)
|
||||
return n
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
@@ -64,7 +64,8 @@ class TestMultiImage():
|
||||
def setUp(self):
|
||||
# This multipage TIF file was created with imagemagick:
|
||||
# convert im1.tif im2.tif -adjoin multipage.tif
|
||||
self.img = MultiImage(os.path.join(data_dir, 'multipage.tif'))
|
||||
if PIL_available:
|
||||
self.img = MultiImage(os.path.join(data_dir, 'multipage.tif'))
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_len(self):
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
import os.path
|
||||
import numpy as np
|
||||
from numpy.testing import *
|
||||
from numpy.testing.decorators import skipif
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from scikits.image import data_dir
|
||||
from scikits.image.io import imread, imsave, use_plugin
|
||||
from scikits.image.io._plugins.pil_plugin import _palette_is_grayscale
|
||||
|
||||
use_plugin('pil')
|
||||
try:
|
||||
from PIL import Image
|
||||
from scikits.image.io._plugins.pil_plugin import _palette_is_grayscale
|
||||
use_plugin('pil')
|
||||
except ImportError:
|
||||
PIL_available = False
|
||||
else:
|
||||
PIL_available = True
|
||||
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_imread_flatten():
|
||||
# a color image is flattened
|
||||
img = imread(os.path.join(data_dir, 'color.png'), flatten=True)
|
||||
@@ -19,12 +28,14 @@ def test_imread_flatten():
|
||||
# check that flattening does not occur for an image that is grey already.
|
||||
assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_imread_palette():
|
||||
img = imread(os.path.join(data_dir, 'palette_gray.png'))
|
||||
assert img.ndim == 2
|
||||
img = imread(os.path.join(data_dir, 'palette_color.png'))
|
||||
assert img.ndim == 3
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_palette_is_gray():
|
||||
from PIL import Image
|
||||
gray = Image.open(os.path.join(data_dir, 'palette_gray.png'))
|
||||
@@ -42,6 +53,7 @@ class TestSave:
|
||||
|
||||
assert_array_almost_equal((x * scaling).astype(np.int32), y)
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_imsave_roundtrip(self):
|
||||
for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]:
|
||||
for dtype in (np.uint8, np.uint16, np.float32, np.float64):
|
||||
|
||||
@@ -2,9 +2,24 @@ from numpy.testing import *
|
||||
|
||||
from scikits.image import io
|
||||
from scikits.image.io._plugins import plugin
|
||||
from numpy.testing.decorators import skipif
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
try:
|
||||
io.use_plugin('pil')
|
||||
PIL_available = True
|
||||
priority_plugin = 'pil'
|
||||
except ImportError:
|
||||
PIL_available = False
|
||||
|
||||
try:
|
||||
io.use_plugin('freeimage')
|
||||
FI_available = True
|
||||
priority_plugin = 'freeimage'
|
||||
except ImportError:
|
||||
FI_available = False
|
||||
|
||||
|
||||
def setup_module(self):
|
||||
self.backup_plugin_store = deepcopy(plugin.plugin_store)
|
||||
@@ -34,11 +49,12 @@ class TestPlugin:
|
||||
def test_failed_use(self):
|
||||
plugin.use('asd')
|
||||
|
||||
@skipif(not PIL_available and not FI_available)
|
||||
def test_use_priority(self):
|
||||
plugin.use('pil')
|
||||
plugin.use(priority_plugin)
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
print(plugin.plugin_store)
|
||||
assert_equal(plug, 'pil')
|
||||
assert_equal(plug, priority_plugin)
|
||||
|
||||
plugin.use('test')
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
|
||||
@@ -2,12 +2,13 @@ import numpy as np
|
||||
from nose.tools import *
|
||||
from numpy.testing import assert_array_equal, assert_array_almost_equal, \
|
||||
assert_equal, run_module_suite
|
||||
from tempfile import TemporaryFile
|
||||
from tempfile import NamedTemporaryFile
|
||||
import os
|
||||
|
||||
from scikits.image.io import load_sift, load_surf
|
||||
|
||||
def test_load_sift():
|
||||
f = TemporaryFile()
|
||||
f = NamedTemporaryFile(delete=False)
|
||||
fname = f.name
|
||||
f.close()
|
||||
f = open(fname, 'wb')
|
||||
@@ -32,6 +33,7 @@ def test_load_sift():
|
||||
f = open(fname, 'rb')
|
||||
features = load_sift(f)
|
||||
f.close()
|
||||
os.remove(fname)
|
||||
|
||||
assert_equal(len(features), 2)
|
||||
assert_equal(len(features['data'][0]), 128)
|
||||
@@ -39,7 +41,7 @@ def test_load_sift():
|
||||
assert_equal(features['column'][1], 99.75)
|
||||
|
||||
def test_load_surf():
|
||||
f = TemporaryFile()
|
||||
f = NamedTemporaryFile(delete=False)
|
||||
fname = f.name
|
||||
f.close()
|
||||
f = open(fname, 'wb')
|
||||
@@ -51,6 +53,7 @@ def test_load_surf():
|
||||
f = open(fname, 'rb')
|
||||
features = load_surf(f)
|
||||
f.close()
|
||||
os.remove(fname)
|
||||
|
||||
assert_equal(len(features), 2)
|
||||
assert_equal(len(features['data'][0]), 64)
|
||||
|
||||
Reference in New Issue
Block a user