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

silx.gui.colors: Add "percentile" mode for autoscaling #4154

Merged
merged 6 commits into from
Oct 7, 2024

Conversation

clemisch
Copy link
Contributor

@clemisch clemisch commented Aug 5, 2024

It autoscales from 1st to 99th (nan)percentiles of the data. In my experience this usually gives a sensible value window for realistic data.

It autoscales from 1st to 99th (nan)percentiles of data.
src/silx/gui/colors.py Outdated Show resolved Hide resolved
@woutdenolf
Copy link
Contributor

woutdenolf commented Aug 13, 2024

Adding PERCENTILE_1_99 to the tests would be a bonus. Look for STDDEV3 in the tests.

@vallsv
Copy link
Contributor

vallsv commented Aug 14, 2024

Hi and thx for the feature.

What do you mean by realistic data? Is that a specific use case or domain?
Could it be possible to have a screenshot with and without?

Also a percentile is like a mean, it's a sort on the values of millions of pixels, right?

The following this processes twice the same sort

numpy.nanpercentile(i, 1)
numpy.nanpercentile(i, 99)

Could you please check if numpy can do something faster the following way?

numpy.nanpercentile(i, [1, 99])

@clemisch
Copy link
Contributor Author

clemisch commented Aug 15, 2024

What do you mean by realistic data? Is that a specific use case or domain?

There is no specific usecase or domain. With "realistic" I mean that it works well on noisy data, data which has artefacts outside of the region of interest, or a simulation which has extreme values only in a very small ratio of pixels. Min/max scaling would scale to the extreme values and not provide good contrast on the "main" content.

In other words, you get good linear contrast for the central 98% of the data.

The extisting mean+-std method only works for values around one mean value. This doesn't apply to many imaging examples where you have a value range inside some min/max but said "extreme" values on top.


Could it be possible to have a screenshot with and without?

Simulation of Fresnel propagation without noise (min/max and percentile scaling):

image

Noisy tomo reco:

image

Admittedly not the most impressive examples. I'm on a conference without good access to real data. In any case, 1-99 percentile scaling is the go-to autowindow of everyone in my x-ray imaging / tomography bubble.


Could you please check if numpy can do something faster the following way?

Yeah, numpy is indeed able to compute both percentiles simultaneously. This doesn't seem to be a recent addition so I'm not sure why I didn't use it so far. I changed the code to use it.

@t20100 t20100 added this to the Next release milestone Aug 26, 2024
@t20100
Copy link
Member

t20100 commented Oct 7, 2024

Hi @clemisch,

I've added some basic tests and reworked the code a bit, it's in this PR on your branch: clemisch#1

Add tests for percentile 1-99 autoscale + make percentile more resilient
@clemisch
Copy link
Contributor Author

clemisch commented Oct 7, 2024

Oh dang, I forgot to add the tests! Thank you for adding them, and props for committing into my branch despite my neglect 😲

@t20100 t20100 merged commit 68c65f1 into silx-kit:main Oct 7, 2024
8 of 10 checks passed
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.

4 participants