Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Formats readable by pims include:

PIMS is based on readers by:
* [scikit-image](http://scikit-image.org/)
* [matplotlib](http://matplotlib.org/)
* [ffmpeg](https://www.ffmpeg.org/) and [PyAV](http://mikeboers.github.io/PyAV/) (video formats such as AVI, MOV)
* [jpype](http://jpype.readthedocs.org/en/latest/) (interface with Bio-formats)
* [Pillow](http://pillow.readthedocs.org/en/latest/) (improved TIFF support)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/image_sequence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ popular formats like PNG, JPG, TIFF, and others. PIMS requires **one of
the following** packages, in order of decreasing preference.

* `scikit-image <http://scikit-image.org/>`_
* `matplotlib <http://matplotlib.org/>`_
* `imageio <https://imageio.github.io/>`_

Scikit-image is installed with the PIMS conda package.
30 changes: 4 additions & 26 deletions pims/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,13 @@
from pims.base_frames import FramesSequence, FramesSequenceND
from pims.frame import Frame

# If scikit-image is not available, use matplotlib (with a warning) instead.
import warnings
try:
from skimage.io import imread
except ImportError:
try:
from matplotlib.pyplot import imread
# imread() works differently between scikit-image and matplotlib.
# We don't require users to have scikit-image,
# but if we fall back to matplotlib, make sure the user
# is aware of the consequences.
ski_preferred = ("PIMS image_reader.py could not find scikit-image. "
"Falling back to matplotlib's imread(), which uses floats "
"instead of integers. This may break your scripts. \n"
"(To ignore this warning, include the line "
'"warnings.simplefilter("ignore", RuntimeWarning)" '
"in your script.)")
warnings.warn(RuntimeWarning(ski_preferred))
except ImportError:
imread = None
import imageio

def imread(*args, **kwargs): # Strip metadata for consistency.
return np.asarray(imageio.imread(*args, **kwargs))


class ImageReader(FramesSequence):
Expand All @@ -40,11 +27,6 @@ def class_exts(cls):
class_priority = 12

def __init__(self, filename, **kwargs):
if imread is None:
raise ImportError("One of the following packages are required for "
"using the ImageReader: "
"matplotlib or scikit-image.")

self._data = imread(filename, **kwargs)

def get_frame(self, i):
Expand Down Expand Up @@ -74,10 +56,6 @@ def class_exts(cls):
class_priority = 11

def __init__(self, filename, **kwargs):
if imread is None:
raise ImportError("One of the following packages are required for "
"using the ImageReaderND: "
"matplotlib or scikit-image.")
super(ImageReaderND, self).__init__()

self._data = Frame(imread(filename, **kwargs), frame_no=0)
Expand Down
21 changes: 3 additions & 18 deletions pims/image_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@
import pims
from pims.base_frames import FramesSequence, FramesSequenceND
from pims.frame import Frame
from pims.image_reader import imread
from pims.utils.sort import natural_keys

# skimage.io.plugin_order() gives a nice hierarchy of implementations of imread.
# If skimage is not available, go down our own hard-coded hierarchy.
has_skimage = False
try:
from skimage.io import imread
has_skimage = True
except ImportError:
try:
from matplotlib.pyplot import imread
except ImportError:
imread = None


class ImageSequence(FramesSequence):
"""Read a directory of sequentially numbered image files into an
Expand Down Expand Up @@ -68,11 +57,11 @@ class ImageSequence(FramesSequence):
>>> frame_shape = video.frame_shape # Pixel dimensions of video
"""
def __init__(self, path_spec, plugin=None):
if not has_skimage:
if not imread.__module__.startswith("skimage"):
if plugin is not None:
warn("A plugin was specified but ignored. Plugins can only "
"be specified if scikit-image is available. Instead, "
"ImageSequence will try using matplotlib")
"ImageSequence will use imageio")
self.kwargs = dict()
else:
self.kwargs = dict(plugin=plugin)
Expand All @@ -94,10 +83,6 @@ def __del__(self):
self.close()

def imread(self, filename, **kwargs):
if imread is None:
raise ImportError("One of the following packages are required for "
"using the ImageSequence reader: "
"scikit-image or matplotlib.")
if self._is_zipfile:
file_handle = BytesIO(self._zipfile.read(filename))
return imread(file_handle, **kwargs)
Expand Down
21 changes: 0 additions & 21 deletions pims/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,13 @@ def _skip_if_no_tifffile():
raise unittest.SkipTest('tifffile not installed. Skipping.')


def _skip_if_no_imread():
if pims.image_sequence.imread is None:
raise unittest.SkipTest('ImageSequence requires either matplotlib or'
' scikit-image. Skipping.')


def _skip_if_no_skimage():
try:
import skimage
except ImportError:
raise unittest.SkipTest('skimage not installed. Skipping.')


def _skip_if_no_PIL():
import pims.tiff_stack
if not pims.tiff_stack.PIL_available():
raise unittest.SkipTest('PIL/Pillow not installed. Skipping.')


def assert_image_equal(actual, expected):
if np.issubdtype(actual.dtype, np.integer):
assert_equal(actual, expected)
Expand Down Expand Up @@ -183,7 +171,6 @@ def compare_slice_to_list(actual, expected):
class TestRecursiveSlicing(unittest.TestCase):

def setUp(self):
_skip_if_no_imread()
class DemoReader(pims.ImageSequence):
def imread(self, filename, **kwargs):
return np.array([[filename]])
Expand Down Expand Up @@ -382,7 +369,6 @@ def test_simple_negative_index(self):

class TestImageReaderTIFF(_image_single, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filename = os.path.join(path, 'stuck.tif')
self.frame0 = np.load(os.path.join(path, 'stuck_frame0.npy'))
self.frame1 = np.load(os.path.join(path, 'stuck_frame1.npy'))
Expand All @@ -395,7 +381,6 @@ def setUp(self):

class TestImageReaderPNG(_image_single, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.klass = pims.ImageReader
self.kwargs = dict()
self.expected_shape = (10, 11)
Expand All @@ -408,7 +393,6 @@ def setUp(self):

class TestImageReaderND(_image_single, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.klass = pims.ImageReaderND
self.kwargs = dict()
self.expected_shape = (10, 11, 3)
Expand Down Expand Up @@ -516,7 +500,6 @@ def check_skip(self):
pass

def setUp(self):
_skip_if_no_PIL()
self.filename = os.path.join(path, 'stuck.tif')
self.frame0 = np.load(os.path.join(path, 'stuck_frame0.npy'))
self.frame1 = np.load(os.path.join(path, 'stuck_frame1.npy'))
Expand Down Expand Up @@ -572,9 +555,6 @@ def test_metadata(self):


class TestOpenFiles(unittest.TestCase):
def setUp(self):
_skip_if_no_PIL()

def test_open_png(self):
self.filenames = ['dummy_png.png']
shape = (10, 11)
Expand All @@ -583,7 +563,6 @@ def test_open_png(self):
clean_dummy_png(path, self.filenames)

def test_open_pngs(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence')
self.filenames = ['T76S3F00001.png', 'T76S3F00002.png',
'T76S3F00003.png', 'T76S3F00004.png',
Expand Down
8 changes: 0 additions & 8 deletions pims/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
from pims.frame import Frame


def _skip_if_no_PIL():
try:
from PIL import Image
except ImportError:
raise unittest.SkipTest('PIL/Pillow not installed. Skipping.')


def _skip_if_no_jinja2():
try:
import jinja2
Expand All @@ -39,7 +32,6 @@ def test_creation_md():


def test_repr_html_():
_skip_if_no_PIL()
_skip_if_no_jinja2()
# This confims a bugfix, where 16-bit images would raise
# an error.
Expand Down
7 changes: 1 addition & 6 deletions pims/tests/test_imseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from pims.tests.test_common import (_image_series,
clean_dummy_png, save_dummy_png,
_skip_if_no_skimage, _skip_if_no_imread)
_skip_if_no_skimage)

path, _ = os.path.split(os.path.abspath(__file__))
path = os.path.join(path, 'data')
Expand Down Expand Up @@ -83,7 +83,6 @@ def tearDown(self):

class TestImageSequenceAcceptsList(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence')
self.filenames = ['T76S3F00001.png', 'T76S3F00002.png',
'T76S3F00003.png', 'T76S3F00004.png',
Expand All @@ -107,7 +106,6 @@ def tearDown(self):

class TestImageSequenceNaturalSorting(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence')
self.filenames = ['T76S3F1.png', 'T76S3F20.png',
'T76S3F3.png', 'T76S3F4.png',
Expand Down Expand Up @@ -150,7 +148,6 @@ def tearDown(self):

class ImageSequenceND(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence3d')
self.filenames = ['file_t001_z001_c1.png',
'file_t001_z001_c2.png',
Expand Down Expand Up @@ -212,7 +209,6 @@ def test_sizeC(self):

class ImageSequenceND_RGB(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence3d')
self.filenames = ['file_t001_z001_c1.png',
'file_t001_z002_c1.png',
Expand Down Expand Up @@ -249,7 +245,6 @@ def tearDown(self):

class ReaderSequence(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
self.filepath = os.path.join(path, 'image_sequence3d')
self.filenames = ['file001.png',
'file002.png',
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
cmdclass=versioneer.get_cmdclass(),
description="Python Image Sequence",
author="PIMS Contributors",
install_requires=['slicerator>=0.9.8', 'six>=1.8', 'numpy>=1.19'],
install_requires=[
'imageio',
'numpy>=1.19',
'six>=1.8',
'slicerator>=0.9.8',
],
author_email="dallan@pha.jhu.edu",
url="https://github.com/soft-matter/pims",
packages=["pims", "pims.utils", "pims.tests"],
Expand Down