Skip to content
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

FIX: Image scaling for large dynamic range ints #10133

Merged
merged 1 commit into from Jan 15, 2018

Conversation

Projects
None yet
4 participants
@jklymak
Copy link
Contributor

commented Dec 30, 2017

PR Summary

This fixes #10072.

The problem was that for a uint32 image, the dynamic range was too high for a float32 to properly represent. Simply changing to float64 fixes the issue. I suppose someone could use a unit64 image, but...

Test coming: code:

import matplotlib.pyplot as plt
import numpy as np

img = np.load('/Users/jklymak/downloads/test_image.npy')
img = np.array([[1, 2, 3], [1, 2, 10000000000]], dtype=np.uint32)
#Display full image
plt.imshow(img, interpolation = 'nearest')
plt.clim(0, 5.)
plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way
@anntzer

This comment has been minimized.

Copy link
Contributor

commented Dec 30, 2017

That's not going to help the efforts on trying to reduce the memory footprint of imshow... (#6952, #8143, etc.). Not a blocker, but should be kept in mind.

@jklymak

This comment has been minimized.

Copy link
Contributor Author

commented Dec 30, 2017

Yeah, understood. This is the dumbest solution.

I don't quite understand why this rescaling is necessary, despite the nice comments....

@jklymak

This comment has been minimized.

Copy link
Contributor Author

commented Dec 30, 2017

OK, I only used the bigger float64 if the amin-amax > 1e8.

@anntzer

This comment has been minimized.

Copy link
Contributor

commented Dec 30, 2017

I think(?) you probably care more about maxabs/minabs.

@jklymak

This comment has been minimized.

Copy link
Contributor Author

commented Dec 30, 2017

Hmmm, not at all sure, because I once understood all the low-level reps of floats etc, but not so good at it anymore. Happy if someone wants to pick this up and do it better.

But, I think the error comes in when we do:

if a_min != a_max:
A_scaled /= ((a_max - a_min) / 0.8)

and the resulting float doesn't preserve all the bits in the unit32.

@jklymak jklymak added this to the v2.1.2 milestone Dec 30, 2017

@tacaswell

This comment has been minimized.

Copy link
Member

commented Dec 30, 2017

This is a reasonable approach.

The scaling is to be able to track the over/under pixels and get around ringing in the interpolations.

@tacaswell

This comment has been minimized.

Copy link
Member

commented Jan 8, 2018

Discussed this on the phone call. Will investigate

  • delaying conversion to float as long as possible
  • avoiding float128 due to platform-dependence
  • add a test

@jklymak jklymak force-pushed the jklymak:fix-image-scaling branch from 5415e6a to 9ba75dc Jan 9, 2018

@jklymak

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2018

Test added, and changes requested above made... Thanks!

@dopplershift
Copy link
Contributor

left a comment

Working and slow is better than broken and fast. Happy to merge a future PR that keeps things working and makes it faster.

@dopplershift dopplershift merged commit b511bb2 into matplotlib:master Jan 15, 2018

5 checks passed

ci/circleci: docs-python27 Your tests passed on CircleCI!
Details
ci/circleci: docs-python35 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
lgtm analysis: Python No alert changes
Details

meeseeksdev bot pushed a commit that referenced this pull request Jan 15, 2018

@jklymak jklymak deleted the jklymak:fix-image-scaling branch Jan 15, 2018

jklymak added a commit that referenced this pull request Jan 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.