-
Notifications
You must be signed in to change notification settings - Fork 8
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
How does create_overlay_data work? #56
Comments
I'm struggling to get Starting with the all_features example, I've modified this line to be
But the example shows only an overlay in red. Looking at the implementation, I'm wondering if somehow the data is not being properly mapped to the color map or if its not passed into the function correctly. I've verified that the colormap variable is created by copying lines 90 to 120 into my script; the value of colormap is:
|
There is this example (referenced from the readme) that uses @rafmudaf what does your mask look like? A minimal working example demonstrating the problem would help narrow things down :) |
Hi @almarklein Thanks for pointing out that example. I looked through but it is quite complex. I actually found that one of the examples in the slicer repo has multiple colors in the overlay: https://github.com/plotly/dash-slicer/blob/main/examples/threshold_overlay.py. This example pointed out the critical point that the mask should be successively added to in order to map bins of data to the index of their color in the colormap. The mask is essentially an index-mapping of all points in the data set to a color in the colormap. In retrospect, this is clear, but it isn't obvious when you don't know what you're looking for. I've opened a pull request showing this at #57. No need to merge, I just wanted to show you the code. |
For future reference, here's a code snippet of mapping a mask to a colormap: COLORMAP = px.colors.sequential.Turbo
def apply_levels(level):
n_bins = len(COLORMAP)
mask = np.zeros(vol.shape, np.uint8)
data_range = vol.max() - vol.min()
thresholds = [ vol.min() + i * data_range / n_bins for i in range(1,n_bins + 1) ]
for i in range(n_bins):
mask += vol < thresholds[i]
return slicer.create_overlay_data(mask, COLORMAP) |
Indeed. I'm glad that you figured it out! Nevertheless, it looks like this is something that we could document more clearly. Would you be interested in creating a PR to update the docstring of Out of curiosity, how did you (initially) think that the colors would be applied based on the mask? |
It would be nice to have a working example in the dash docs
The text was updated successfully, but these errors were encountered: