Skip to content

Fix image interpolation #8966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 31, 2017
Merged

Conversation

tacaswell
Copy link
Member

@tacaswell tacaswell commented Jul 30, 2017

This is an attempt at #8631 and #6952

I expect this to fail. Already updated a bunch of images that had minor changes. There are a few with big changes that I still need to look into.

  • re-visit rotate image and get rid of black pixels on edge
  • drop attempt to fix python2
  • add comments about ringing into test code
  • look into scaling to a bit less than full range to prevent speckles near vmin/vmax
  • test flat cases near vmin or vmax\
  • regenerate all test images with current defaults

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jul 30, 2017
@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jul 30, 2017
@anntzer
Copy link
Contributor

anntzer commented Jul 31, 2017

In rotate_image.png, the edge of the image seems to follow the middle of the dashes more closely in the original version.

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

👍 on the approach--interpolating before doing any other transforms makes sense to me. I'm also a little concerned about the change to rotate_image, but no clue what's going wrong.

Caught a couple typos in the comments.


# we are done with A_scaled now, remove from namespace to be sure!
del A_scaled
# un-scale the resampled data to approximatly the
Copy link
Contributor

Choose a reason for hiding this comment

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

approximatly -> approximate

self.get_filterrad() or 0.0)
# we are done with the mask, delete from namespace to be sure!
del mask
# Agg tells us a pixel has no value not setting a value into it
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a word missing in this comment.

@tacaswell
Copy link
Member Author

I anticipate re-writing history here before it gets merged.

@tacaswell
Copy link
Member Author

I see some failures locally that I do not understand, let see if we see them on travis.

Still have to sort out those edge effects.

History will get re-written at least once more before this is ready to merge.

@tacaswell
Copy link
Member Author

I am actually comfertable that the edges are the correct behavior. If you look at the zoomed in bottom 3x3 area

so

you can see that the out of range area is against the edge, the bottom right is the highest value which is equal to vmax of the norm.

It is correct, from the interpolations point of view, that the pixel past the last point (which it view as being at the center of that pixel) are of greater value (which are then correctly marked as out of range).

@tacaswell tacaswell force-pushed the fix_image_interpolation branch from c511460 to db19f9f Compare August 7, 2017 02:39
@tacaswell tacaswell changed the title [WIP] Fix image interpolation Fix image interpolation Aug 7, 2017
@tacaswell tacaswell force-pushed the fix_image_interpolation branch from 1962d84 to 1e160aa Compare August 7, 2017 19:07
@tacaswell
Copy link
Member Author

tacaswell commented Aug 7, 2017

Todos:

  • re-visit rotate image and get rid of black pixels on edge
  • drop attempt to fix python2
  • add comments about ringing into test code
  • look into scaling to a bit less than full range to prevent speckles near vmin/vmax
  • test flat cases near vmin or vmax\
  • regenerate all test images with current defaults

@tacaswell tacaswell mentioned this pull request Aug 7, 2017
@tacaswell tacaswell modified the milestone: 2.1 (next point release) Aug 29, 2017
 - interpolate raw, not normed, data
 - should reduce memory footprint, only 1 or 2 copies of input data
 - this will change many tests in small ways
 - down-casting input data before interpolation was causing issues with
   numerical precision so work in no less than the input float type
 - Numpy 1.7 does not support `np.nanmin` and `np.nanmax` on masked
   arrays (instead of returning a number it returns a MaskedIterator).
 - update to mpl20 style
 - re-generate as needed
 - bump threshold on pngsuite test
@tacaswell tacaswell force-pushed the fix_image_interpolation branch from 1e160aa to ec43d0e Compare August 29, 2017 03:14
@tacaswell tacaswell added this to the 2.1 (next point release) milestone Aug 29, 2017
@tacaswell
Copy link
Member Author

from copy import copy
import matplotlib.image as mimage
def interpolation_grid(data, vmin=None, vmax=None):
    cm = copy(plt.get_cmap('viridis'))
    cm.set_over('r')
    cm.set_under('b')
    cm.set_bad('k')
    
    fig, ax_grid = plt.subplots(3, 6, sharex=True, sharey=True)

    ret = []
    for interp, ax in zip(sorted(mimage._interpd_), ax_grid.ravel()):
        ax.set_title(interp)
        im = ax.imshow(data, cmap=cm, interpolation=interp)
        ax.axis('off')
        im.set_clim(vmin, vmax)
        ret.append(im)
    return ret
ims_a = interpolation_grid([[0, 1], [1, 0]], 0, 1)
ims_b = interpolation_grid(np.tile([[0, 1], [1, 0]], (10, 10)), 0, 1)

I am satisfied that the speckles are edge effects on the higher-order interpolators

[im.set_clim(0, 1.00000005) for im in ims_b]

That is the smallest upper limit that shows the speckles on my system which gives us an idea of the level of the numeric instability. I don't think that it is worth playing games to stay just under it as I suspect it will vary between systems.

If we do anything about this we should bump the Autoscales out a bit.

Push the stale flag down into the ScalarMappable so that it gets
applied to all ScalarMappable sub-classes (ex Collections).
@tacaswell tacaswell force-pushed the fix_image_interpolation branch from 8186243 to 346bb1a Compare August 31, 2017 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants