Skip to content

WIP: Remove inconsistencies in scipy.misc / scipy.ndimage#7259

Closed
MartinThoma wants to merge 1 commit intoscipy:masterfrom
MartinThoma:image-misc
Closed

WIP: Remove inconsistencies in scipy.misc / scipy.ndimage#7259
MartinThoma wants to merge 1 commit intoscipy:masterfrom
MartinThoma:image-misc

Conversation

@MartinThoma
Copy link
Copy Markdown
Contributor

  • Move scipy.misc.imfilter to scipy.ndimage.imfilter
  • Move scipy.misc.imresize to scipy.ndimage.imresize
  • Move scipy.misc.imrotate to scipy.ndimage.imrotate

Fixes #6242

@MartinThoma
Copy link
Copy Markdown
Contributor Author

There is still quite a bit to be done for this one. However, I wanted to make this pull request to run the tests (when I execute runtests.py on my machine I get a lot of errors which seem to be unrelated).

@MartinThoma
Copy link
Copy Markdown
Contributor Author

Could somebody please explain why importing toimage does not work anymore?

======================================================================
ERROR: test_pilutil.test_imread_4bit
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/local/lib/python2.7/dist-packages/numpy/testing/decorators.py", line 147, in skipper_func
    return f(*args, **kwargs)
  File "/home/moose/GitHub/scipy/build/testenv/lib/python2.7/site-packages/scipy/misc/tests/test_pilutil.py", line 201, in test_imread_4bit
    im = misc.imread(f)
AttributeError: 'module' object has no attribute 'imread'

======================================================================
ERROR: Failure: ImportError (cannot import name toimage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/moose/GitHub/scipy/build/testenv/lib/python2.7/site-packages/scipy/ndimage/__init__.py", line 161, in <module>
    from .filters import *
  File "/home/moose/GitHub/scipy/build/testenv/lib/python2.7/site-packages/scipy/ndimage/filters.py", line 37, in <module>
    from scipy.misc import doccer, toimage, fromimage
ImportError: cannot import name toimage

@rgommers rgommers added this to the 1.0 milestone Apr 5, 2017
@rgommers rgommers added maintenance Items related to regular maintenance tasks scipy.misc scipy.ndimage labels Apr 5, 2017
Comment thread scipy/misc/pilutil.py Outdated
__all__ = ['fromimage', 'toimage', 'imsave', 'imread', 'bytescale',
'imrotate', 'imresize', 'imshow', 'imfilter']

from ndimage import imresize, imfilter, imrotate
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, should be from scipy.ndimage ....

Comment thread scipy/misc/pilutil.py Outdated

from ndimage import imresize, imfilter, imrotate
imresize = numpy.deprecate(imresize,
message='misc.imresize is deprecated in Scipy 1.0')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add that the function was moved to ndimage in the message?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gh-6242 had some discussion on whether these functions shouldn't just be deprecated unconditionally (#6242 (comment)). There's something to say for that. Good to get a decision on that first.

@rgommers
Copy link
Copy Markdown
Member

rgommers commented Apr 5, 2017

Could somebody please explain why importing toimage does not work anymore?

That'll be fixed if you correct the ndimage import I just pointed out.

@rgommers
Copy link
Copy Markdown
Member

rgommers commented Apr 5, 2017

I suggest to work on the move of imwrite and imsave to io first, because those are the only two functions that we clearly want to keep.

Need some opinions on the other ones - move to ndimage or just deprecate? It sounded like @WarrenWeckesser was +0.5 on deprecating in gh-6242, and I'd be okay with that as well.

* Move scipy.misc.imfilter to scipy.ndimage.imfilter
* Move scipy.misc.imresize to scipy.ndimage.imresize
* Move scipy.misc.imrotate to scipy.ndimage.imrotate

Fixes #6242
@person142
Copy link
Copy Markdown
Member

I like deprecate too. If we were to want similar functions in ndimage, IMO it makes more sense to rewrite them from scratch so that they don't rely on Pillow, work in nd, and have a better API (no mode stuff).

@rgommers rgommers removed this from the 1.0.0 milestone Sep 13, 2017
@rgommers
Copy link
Copy Markdown
Member

We're not going to get to the misc cleanup for 1.0, removing the milestone for this.

@rgommers
Copy link
Copy Markdown
Member

We're not going to get to the misc cleanup for 1.0, removing the milestone for this.

Changing my mind, it's an awful mess. We should just get all the deprecations in.

rgommers added a commit to rgommers/scipy that referenced this pull request Sep 16, 2017
The reasons for these deprecations are:
  1. Many of the functions have bugs and unexpected behavior.
  2. There are better alternatives for pretty much every function.

Summary of issues:

- ``imsave`` rescales images (scipygh-5305)
- ``imresize`` rescales images (scipygh-4458) and casts to different dtype (scipygh-6417)
- Many functions suffer from a shape handling bug for (3, 100, 3) RGB and
  (4, 100, 4) RGBA images (scipygh-2347)
- ``toimage`` is the root cause of casting and scaling issues, one more
  separate bug report at scipygh-2300
- ``imfilter``, ``imrotate`` and ``imshow`` don't have a bug reported against
  them, but suffer from casting/rescaling as well.

The functions that seem sort of OK:
- ``imread``. Exposed also as ``ndimage.imread``.  Want to move to ``scipy.io``
  Also note the discussion in
  scipy#6242 (comment) about
  ``imsave``. Want to rename to ``imwrite`` and move to ``scipy.io`` (or write
  a new one without the rescaling issues and put that in ``io``).
- ``fromimage``.  Changes PIL image to ndarray.
- ``bytescale``.  Does some simple scaling of range of an array.

Closes scipygh-2347
Closes scipygh-2300
Closes scipygh-2442
Closes scipygh-3154
Closes scipygh-4458
Closes scipygh-4893
Closes scipygh-5305
Closes scipygh-6242
Closes scipygh-6417
Closes scipygh-7259
Closes scipygh-7458

See discussion about introducing scipy.io.imread/imwrite in
http://thread.gmane.org/gmane.comp.python.scientific.devel/20063
I didn't actually do that here, seems duplicate with matplotlib,
scikit-image, etc.  Can always be done separately if deemed a good
idea.  See also PR scipygh-5458 that make an attempt at this.
rgommers added a commit to rgommers/scipy that referenced this pull request Sep 16, 2017
The reasons for these deprecations are:
  1. Many of the functions have bugs and unexpected behavior.
  2. There are better alternatives for pretty much every function.

Summary of issues:

- ``imsave`` rescales images (scipygh-5305)
- ``imresize`` rescales images (scipygh-4458) and casts to different dtype (scipygh-6417)
- Many functions suffer from a shape handling bug for (3, 100, 3) RGB and
  (4, 100, 4) RGBA images (scipygh-2347)
- ``toimage`` is the root cause of casting and scaling issues, one more
  separate bug report at scipygh-2300
- ``imfilter``, ``imrotate`` and ``imshow`` don't have a bug reported against
  them, but suffer from casting/rescaling as well.

The functions that seem sort of OK:
- ``imread``. Exposed also as ``ndimage.imread``.  Want to move to ``scipy.io``
  Also note the discussion in
  scipy#6242 (comment) about
  ``imsave``. Want to rename to ``imwrite`` and move to ``scipy.io`` (or write
  a new one without the rescaling issues and put that in ``io``).
- ``fromimage``.  Changes PIL image to ndarray.
- ``bytescale``.  Does some simple scaling of range of an array.

Closes scipygh-2347
Closes scipygh-2300
Closes scipygh-2442
Closes scipygh-3154
Closes scipygh-4458
Closes scipygh-4893
Closes scipygh-5305
Closes scipygh-6242
Closes scipygh-6417
Closes scipygh-7259
Closes scipygh-7458

See discussion about introducing scipy.io.imread/imwrite in
http://thread.gmane.org/gmane.comp.python.scientific.devel/20063
I didn't actually do that here, seems duplicate with matplotlib,
scikit-image, etc.  Can always be done separately if deemed a good
idea.  See also PR scipygh-5458 that make an attempt at this.
@rgommers
Copy link
Copy Markdown
Member

Thanks for having a go at this @MartinThoma! We're deprecating the pilutil functions instead of moving them, so I'm closing this PR.

@rgommers rgommers closed this Sep 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Items related to regular maintenance tasks scipy.misc scipy.ndimage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants