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

jklymak
Copy link
Member

@jklymak jklymak 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
Copy link
Contributor

anntzer 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
Copy link
Member Author

jklymak 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
Copy link
Member Author

jklymak commented Dec 30, 2017

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

@anntzer
Copy link
Contributor

anntzer commented Dec 30, 2017

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

@jklymak
Copy link
Member Author

jklymak 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
Copy link
Member

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
Copy link
Member

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
Copy link
Member Author

jklymak commented Jan 9, 2018

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

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

imshow doesn't properly display some images
4 participants