Repository navigation
Keep the LUT range in data units with the Z-axis log scale (color bar, contrast panel) - #86
Merged
Merged
Conversation
With the Z-axis logarithmic scale, the LUT range of image items was expressed in base-10 logarithms: the color bar showed logarithms of the image values, the contrast adjustment panel mixed a histogram of the data with a range of logarithms (so that "Full range" or "Eliminate %" showed the image with a single color), and cross sections or exported images with the LUT applied mixed data with log coefficients. The LUT range now always uses data units: only the color mapping is logarithmic (like matplotlib's LogNorm). - `set_lut_range` stores data units and computes the LUT coefficients from the logarithms of the bounds; `get_lut_range_full` and `set_data` follow the same convention - Values lower than or equal to zero are replaced by the smallest positive value of the data instead of 1 (`clip(1)`), so that data lower than 1 is no longer shown with a single color - Enabling the log scale sets the full range of the positive values, disabling it restores the previous LUT range; enabling it twice no longer overwrites the saved range - The color bar uses a logarithmic scale engine, with bounds in data units, and the new `LogScaleColorMap` so that its colors match the image - Cross sections and `export_roi` with `apply_lut=True` use the log data; the anti-aliasing kernel follows the data type of the data drawn - New `BaseImageItem.supports_zaxis_log`: RGB images, 2D histograms, quadrilateral grids and image filters, which do not draw the log data, are ignored by `ZAxisLogTool` and `set_zaxis_log_state` - `ZAxisLogTool` notifies the LUT change, so that the contrast panel and other listeners get the new range Closes #63 Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #63.
Problem
With the Z-axis logarithmic scale (
ZAxisLogTool), image items expressed their LUT range (min/max) in base-10 logarithms, whereas the cursor values, the contrast histogram and the image data stay in data units. As a result:apply_lut=True) applied the log coefficients to the data (saturated values);set_data(lut_range=...),keep_lut_range, serialization,ImageAxesParam(z min/max) and downstream applications (e.g. DataLab's Z scale bounds) handled a range whose unit depended on the scale;clip(1)turned every value lower than 1 into 0: data between 0 and 1 was shown with a single color;ZAxisLogToolwas enabled for items which do not draw the log data (RGB images, 2D histograms, quadrilateral grids, image filters).Changes
The LUT range now always uses data units: only the color mapping is logarithmic, as with matplotlib's
LogNorm.Image items (
BaseImageItem)set_lut_rangestores the range in data units and computes the LUT coefficients from the logarithms of the bounds. In log mode, bounds lower than or equal to zero are replaced by the smallest positive value of the data.get_lut_range_fullreturns the full range of the positive values in log mode;set_datauses it when nolut_rangeis given, and an explicitlut_rangeis in data units.set_dataas it would have been without the log scale). Enabling it twice no longer overwrites the saved range._get_display_data(shared bydraw_imageofRawImageItem,ImageItem,XYImageItemandTrImageItem) and_to_lut_space(cross sections).export_roi(apply_lut=True)and cross sections withapply_lut=Trueuse the log data.set_interpolationfollows the data type of the data drawn.supports_zaxis_log():FalseforRGBImageItem,QuadGridItem,Histogram2DItemandImageFilterItem, for whichset_zaxis_log_statehas no effect.Color bar
BasePlot.update_colormap_axisswitches the colormap axis toQwtLogScaleEngine(bounds in data units: decade ticks with minor ticks at 2, 4, 6, 8) and back to a linear scale engine, only when needed.LogScaleColorMap(plotpy.mathutils.colormap) wraps the item colormap so that the colors of the color bar match the image (a log scale engine alone would keep a linear colormap along a logarithmic axis).Tool
ZAxisLogToolonly handles items supporting the log scale, and callsnotify_colormap_changed(): the contrast panel andSIG_LUT_CHANGEDlisteners get the new range.Tests
plotpy/tests/unit/test_image_zaxis_log.py(28 tests including parametrizations overImageItem,XYImageItem,TrImageItem,MaskedImageItem,MaskedXYImageItem):export_roiwith the log LUT;set_datawith and withoutlut_range;LogScaleColorMapcolors (with inverted colormaps);test_image_log_set_data.pyupdated to data units;test_zaxislog.pychecks the color bar scale.Notes
get_lut_range,set_lut_range,get_lut_range_fullandset_data(lut_range=...)now use data units instead of base-10 logarithms (documented in the 2.12.0 release notes). Since the previous behavior was internally inconsistent, this is handled as a bug fix.feat/logscale_colorbarbranch which fixed the color bar labels: this PR takes the same log scale engine approach, and extends it to the colors of the color bar and to the LUT range, so that every consumer of the range sees data units.QuadGridItem, and log colors forImageFilterItemwhen it uses the colormap of a source image in log mode.