Repository: scikit-image/scikit-image

Issue:
imageIO warnings due to v2 -> v3 migration
## Description

As of imageIO 2.16.0 (Feb22) there are now a v2 and v3 namespaces in addition to the top-level namespace.  As of 2.16.2 (released Apr22) directly using the top-level namespace results in warnings to either explicitly opt-into the v3 API or opt-out and import the v2.  

This in turn causes warnings when using `skimage.io.imread`. 

I suggest that this is a good first issue as there is no API design choices here (at least to start) and only needs the 
```python
try: 
    import newway
except ImportError: 
    import old way
```
dance.

The warnings look like (lifted from a test suite):

```
____________________________________________________________________________ ReaderSequence.test_slice_of_slice ____________________________________________________________________________
pims/tests/test_imseq.py:256: in setUp
    self.v = self.klass(self.filename, **self.kwargs)
pims/image_sequence.py:217: in __init__
    with self.reader_cls(self._filepaths[0], **self.kwargs) as reader:
pims/image_reader.py:60: in __init__
    self._data = Frame(imread(filename, **kwargs), frame_no=0)
../../../../.pybuild/bleeding/lib/python3.11/contextlib.py:155: in __exit__
    self.gen.throw(typ, value, traceback)
../../../../.virtualenvs/bleeding/lib/python3.11/site-packages/skimage/io/util.py:43: in file_or_url_context
    yield resource_name
../../../../.virtualenvs/bleeding/lib/python3.11/site-packages/skimage/io/_io.py:53: in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
../../../../.virtualenvs/bleeding/lib/python3.11/site-packages/skimage/io/manage_plugins.py:207: in call_plugin
    return func(*args, **kwargs)
../../../../.virtualenvs/bleeding/lib/python3.11/site-packages/skimage/io/_plugins/imageio_plugin.py:10: in imread
    return np.asarray(imageio_imread(*args, **kwargs))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

uri = '/home/tcaswell/source/bnl/soft-matter/pims/pims/tests/data/image_sequence3d/file001.png', format = None, kwargs = {}

    def imread(uri, format=None, **kwargs):
        """imread(uri, format=None, **kwargs)
    
        Reads an image from the specified file. Returns a numpy array, which
        comes with a dict of meta data at its 'meta' attribute.
    
        Note that the image data is returned as-is, and may not always have
        a dtype of uint8 (and thus may differ from what e.g. PIL returns).
    
        Parameters
        ----------
        uri : {str, pathlib.Path, bytes, file}
            The resource to load the image from, e.g. a filename, pathlib.Path,
            http address or file object, see the docs for more info.
        format : str
            The format to use to read the file. By default imageio selects
            the appropriate for you based on the filename and its contents.
        kwargs : ...
            Further keyword arguments are passed to the reader. See :func:`.help`
            to see what arguments are available for a particular format.
        """
    
>       warnings.warn(
            "Starting with ImageIO v3 the behavior of this function will switch to that of"
            " iio.v3.imread. To keep the current behavior (and make this warning dissapear)"
            " use `import imageio.v2 as imageio` or call `imageio.v2.imread` directly.",
            DeprecationWarning,
        )
E       DeprecationWarning: Starting with ImageIO v3 the behavior of this function will switch to that of iio.v3.imread. To keep the current behavior (and make this warning dissapear) use `import imageio.v2 as imageio` or call `imageio.v2.imread` directly.

../../../../.virtualenvs/bleeding/lib/python3.11/site-packages/imageio/__init__.py:89: DeprecationWarning

```


Discussion:
Thanks @tacaswell. I agree that adding this `try/except` seems like a good solution. We should probably make one more 0.19.x release soon with this and a couple of other recent bug fixes.


Resolving patch:
diff --git a/skimage/io/_plugins/imageio_plugin.py b/skimage/io/_plugins/imageio_plugin.py
--- a/skimage/io/_plugins/imageio_plugin.py
+++ b/skimage/io/_plugins/imageio_plugin.py
@@ -2,7 +2,12 @@
 
 from functools import wraps
 import numpy as np
-from imageio import imread as imageio_imread, imsave
+
+try:
+    # Try using the v2 API directly to avoid a warning from imageio >= 2.16.2
+    from imageio.v2 import imread as imageio_imread, imsave
+except ImportError:
+    from imageio import imread as imageio_imread, imsave
 
 
 @wraps(imageio_imread)


Test patch: