-
Notifications
You must be signed in to change notification settings - Fork 80
colormap: allow users to provide percentile values for 'PERCENTILE' mode #4379
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
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
8aa2c86
silx.gui.plot: Generalize code to use any percentile value and not on…
payno d3d5f4e
from_saturation_to_percentile: add check on input and allow integers
payno 1e62810
ColormapDialog: rework scale widget layout:
payno 3b4a001
ColormapDialog: replace the concept of 'saturation' by a concept of '…
payno 321a68d
Update src/silx/gui/colors.py
payno ea848fc
Update src/silx/gui/colors.py
payno 3ad7889
Update src/silx/gui/colors.py
payno 00e5c22
Update src/silx/gui/colors.py
payno 8259a16
Update src/silx/gui/colors.py
payno cef5665
Update src/silx/gui/colors.py
payno 979037f
Update src/silx/gui/colors.py
payno db1b0a4
Update src/silx/gui/dialog/ColormapDialog.py
payno 04654f7
Colormap: rename '_percentiles_autoscale_values' to '_percentiles'
payno f2afe95
silx.gui.colors: remove duplicated code for computing min/max
payno df98476
Move silx.gui.widgets.SliderWithSpinBox to private
payno 3904be1
SliderWithSpinBox: replace the QDoubleSpinBox by a SpinBox
payno 9cb3839
Revert plotWidget modifications
payno 856c6b2
ColormapDialog: rename 'percentile_range' to 'lateral_percentile_rang…
payno 7146f0d
ColormapDialog: Rename '_usedPercentileWidget' to '_centralPercentile…
payno 72b2bda
ColormapDialog: rename '_updateUsedPercentileVisibility' to '_updateC…
payno c8f8856
Remove: test_contrast_enhancer
payno fb70b7a
silx.math.colormap: fix 'normalize'
payno 0032165
TestAutoscaleRange: fix test
payno 56f7900
black
payno f478fef
silx.gui.colors: fix missing 'Literal'
payno cfe8926
Update src/silx/gui/dialog/ColormapDialog.py
payno d226326
Update src/silx/gui/dialog/ColormapDialog.py
payno 9cbe182
Update src/silx/gui/widgets/_SliderWithSpinBox.py
payno f4624da
Update src/silx/math/colormap.py
payno ae58843
Update src/silx/math/colormap.py
payno 92f4bbb
Update src/silx/math/colormap.py
payno 9c14ced
Colormap.getAutoscalePercentile: update docstring
payno d95b14c
move and rename silx.gui;widgets._SliderWithSpinBox to silx.gui.dialo…
payno 7010d4d
silx.gui.dialog: move ColormapDialog functions 'from_lateral_percenti…
payno 1130cf9
silx.gui.colors: rename Colormap.setAutoscalePercentile to Colormap.s…
payno a7a0d51
silx.match.colormap: update 'AutoScaleModeType'
payno 34bf6dd
ColormapPercentileWidget: rename 'fromCentralPercentileToLateralPerce…
payno 61f8182
Colormap: update _DEFAULT_PERCENTILES to be floats
payno 136d14e
Colormap: use '_DEFAULT_PERCENTILES' to set default values
payno be99993
ColormapRow: remove todo and add an issue instead (https://github.com…
payno b1fa723
silx.gui.colors.Colormap: use 'AutoScaleModeType' instead of redefini…
payno 95df4fd
silx.math.colormap._NormalizationMixIn: if mode 'percentile_1_99' giv…
payno a6c6e3d
silx.math.colormap: rename several 'percentile' to 'percentiles' (the…
payno 2a9bff9
ColormapPercentilesWidget: improve docstring
payno ca20f50
ColormapPercentilesWidget: avoid using 'blocksignals'
payno 823e4a4
Rework ColormapPercentilesWidget:
payno 9e420b3
ColormapDialog: clean unused code
payno f64e2c2
ColormapPercentilesWidget: rework access to 'setSaturationValue' in o…
payno 9978f1b
Update src/silx/gui/colors.py
payno 01a84da
Update src/silx/gui/dialog/_ColormapPercentileWidget.py
payno ac7b863
ColormapPercentilesWidget: rename 'getSaturationValue' and 'setSatura…
payno 809daa1
ColormapPercentilesWidget: move widget fine tuning in the constructor
payno 8958c44
ColormapDialog: removed unecessary set of percentiles
payno c28a550
ColormapPercentilesWidget: store last saturation value to check if ch…
payno 578d53f
ColormapPercentileWidget: remove ununsed import
payno ccc09b4
ColormapDialog: remove unecessary connection.
payno 4f5f5ab
Colormap: improve deprecation warning when using percentile_1_99 in c…
payno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from silx.gui import qt | ||
| from ..colors import Colormap | ||
|
|
||
|
|
||
| class ColormapPercentilesWidget(qt.QWidget): | ||
| """ | ||
| Widget to define the percentiles to be used when computing the colormap in autoscale / percentile mode. | ||
|
|
||
| A scalar value (that can be seen as saturation) is defined by the user and then converted to percentiles using the 'fromSaturationToPercentiles' function. | ||
| """ | ||
|
|
||
| percentilesChanged = qt.Signal(tuple) | ||
|
|
||
| def __init__(self, parent=None): | ||
| super().__init__(parent) | ||
| self._saturationLastValue = None | ||
|
|
||
| self.setLayout(qt.QHBoxLayout()) | ||
|
|
||
| self._slider = qt.QSlider(qt.Qt.Horizontal, self) | ||
| self.layout().addWidget(self._slider) | ||
|
|
||
| self._spinBox = qt.QSpinBox(self) | ||
| self.layout().addWidget(self._spinBox) | ||
|
|
||
| self._setRange(0, 100) | ||
|
|
||
| self.setTickPosition(qt.QSlider.TicksBelow) | ||
|
|
||
| self.setPercentilesRange(Colormap._DEFAULT_PERCENTILES) | ||
| self.setTracking(False) | ||
|
|
||
| # connect signal / slot | ||
| self._slider.valueChanged.connect(self._setSaturation) | ||
| self._spinBox.valueChanged.connect(self._setSaturation) | ||
|
|
||
| def _setSaturation(self, value: int): | ||
| self._slider.setValue(value) | ||
| self._spinBox.setValue(value) | ||
| if self._saturationLastValue != value: | ||
| self._saturationLastValue = value | ||
| self.percentilesChanged.emit(self.getPercentilesRange()) | ||
|
|
||
| def _getSaturation(self) -> int: | ||
| return self._slider.value() | ||
|
|
||
| def _setRange(self, min: int, max: int): | ||
| """ | ||
| Set the slider / spin box range | ||
| """ | ||
| self._slider.setRange(min, max) | ||
| self._spinBox.setRange(min, max) | ||
|
|
||
| def setPercentilesRange(self, percentiles: tuple[float, float]): | ||
| self._setSaturation(self.fromPercentilesToSaturation(percentiles)) | ||
|
|
||
| def getPercentilesRange(self) -> tuple[float, float]: | ||
| return self.fromSaturationToPercentiles(self._getSaturation()) | ||
|
|
||
| # expose API | ||
| def setTickPosition(self, position): | ||
| self._slider.setTickPosition(position) | ||
|
|
||
| def setTracking(self, enable: bool): | ||
| self._slider.setTracking(enable) | ||
|
|
||
| @staticmethod | ||
| def fromPercentilesToSaturation( | ||
| percentiles: tuple[float, float], | ||
| ) -> int: | ||
| """ | ||
| Example: if we want to have saturation = 90% then the percentile we will return percentiles (5th, 95th) | ||
| """ | ||
| return int(100 - (percentiles[0] + (100 - percentiles[1]))) | ||
|
|
||
| @staticmethod | ||
| def fromSaturationToPercentiles( | ||
| saturation: float | int, | ||
| ) -> tuple[float, float]: | ||
| """ | ||
| Example: if we use percentiles (1st, 99th) we use 98% of the percentiles. This is the saturation (can be seen also as the central percentile) | ||
| """ | ||
| if not isinstance(saturation, (float, int)): | ||
| raise TypeError( | ||
| f"central_percentile is expected to be float. Got {type(saturation)}" | ||
| ) | ||
| ignored_percentile = 100 - saturation | ||
| return (ignored_percentile / 2.0, 100 - (ignored_percentile / 2.0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.