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
Add (interactive) slice explorer in plotly. #4953
Conversation
Thanks @mkcor. It's a bit hacky but it works beautifully. I've pushed a commit to your branch because you need to set a specific plotly renderer for sphinx-gallery to integrate correctly the figure. Ideally we would use |
One caveat of using |
@mkcor I made good progress in plotly/plotly.py#2746, so you'll be able to write
( This feature should be available in plotly 4.11 so in a month I believe. In the meantime I'm interested in your feedback if you have the time to do some tests with the corresponding plotly branch! |
@emmanuelle this is great news! :)
For sure! I will update this example, try out the new feature with other datasets as well, and let you know. |
Hiya, I just stumbled across this when searching for a multi-dim microscopy image dataset to use as an example. This looks awesome, and I'm super stoked about all the microscopy data that will be available in version Would you be interested in an example showing how to slice image stacks using For example using hyperslicer with the skimage cells dataset: from mpl_interactions import hyperslicer
fig, ax = plt.subplots()
z_step = 0.0650000
N = cells.shape[0]
z_values = np.linspace(-N / 2, N / 2, cells.shape[0]) * z_step # assume the center is the focus
controls = hyperslicer(cells, axes=(("z", z_values),), play_buttons=True, play_button_pos="left") Suggested exampleI'm nott necessarily suggesting including Happy to hear your thoughts and thanks so much for skimage! |
Got a bit carried away here and found another potential example 😬. Similarl to above question, would you be interested in an example using ipywidgets or matplotlib widgets for varying the values of some transform? e..g adjusting the expsoure (https://scikit-image.org/docs/dev/auto_examples/applications/plot_3d_image_processing.html#adjust-exposure) Like with hyperslicer below example uses mpl_interactions.imshow as it's slightly this easier, but it shouldn't be too complex with just matplotlib + ipywidgets. plt.figure()
plt.imshow(exposure.adjust_gamma(cells[30], 1))
def f(gamma):
return exposure.adjust_gamma(cells[30], gamma)
controls = iplt.imshow(f, gamma = (.5, 4), title="gamma = {gamma:.2f}", play_button_pos='left', play_buttons=True)
plt.tight_layout() |
Hello @ianhi! Thank you for your interest, your contributions, and your patience. Following your inputs, I think I'll split the 'Explore 3D images' tutorial into its main part and the other part about adjusting exposure. Then, we will be more at ease to expand each part with alternative ways in terms of interactive exploration (whether of data slices or parameter values). Otherwise, the example will get too cluttered. As you have seen and read in the example, the downside of Jupyter widgets is that, unlike Plotly figures, they don't render in our docs (static HTML pages). Having said that, I think it's still valuable to include relevant code meant to run with a Jupyter kernel. |
Hi again @ianhi,
Actually, there is already a section dedicated to exposure adjustment in the narrative docs. So how about adding interactive exposure adjustment to this existing example, whether for gamma correction or logarithmic correction? |
@mkcor please checkout the new release of plotly :-). fig = px.imshow(img, animation_frame=0, binary_string=True) and other examples https://plotly.com/python/imshow/#exploring-3d-images-and-timeseries-with-animationframe |
@emmanuelle for sure! I'll update this PR later today :-) |
Hi @mkcor could you please merge master into your branch? The recurring errors in the circleCI doc build are (hopefully) fixed in master, and this way reviewers can look at the generated html pages without fetching your branch. |
@emmanuelle for sure! I forgot that this PR was initially submitted before we added the "Update branch" button... ;-) |
The interactive slice explorer is brilliant! 🎉 As is the fact that we can view rendered docs in PRs! Life is good. =) I have a couple of suggestions for the tutorial:
Thank you! |
Another possibility similar to the For example, to make a montage by tiling every second slice of the data: import skimage.util
data_montage = skimage.util.montage(data[::2])
_, ax = plt.subplots(1)
ax.imshow(data_montage, cmap="gray")
ax.set_axis_off() Specify data_montage = skimage.util.montage(data[::2], padding_width=2, fill=data.max())
_, ax = plt.subplots(1)
ax.imshow(data_montage, cmap="gray")
ax.set_axis_off() |
Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu>
faa8154
to
8aa2d2a
Compare
Co-authored-by: Gregory R. Lee <grlee77@gmail.com>
cf6bfdd as per #5120 (review) @emmanuelle 😉 |
doc/source/conf.py
Outdated
# set plotly renderer to capture _repr_html_ for sphinx-gallery | ||
import plotly.io as pio | ||
pio.renderers.default = 'sphinx_gallery' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the same file, there is also:
scikit-image/doc/source/conf.py
Lines 153 to 157 in 044ac80
# set plotly renderer to capture _repr_html_ for sphinx-gallery | |
import plotly.io as pio | |
pio.renderers.default = 'sphinx_gallery_png' | |
from plotly.io._sg_scraper import plotly_sg_scraper | |
image_scrapers = ('matplotlib', plotly_sg_scraper,) |
and from looking at the Git blame,
pio.renderers.default
wasn't meant to be set in two different places... I tried removing either instance, thinking there might be some unintended conflict, rebuilding the docs with the plotly.io.show(fig)
call, but the figure still wouldn't render in the gallery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falling back on #5346 then... 😞 @emmanuelle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grlee77 @emmanuelle sorry for the false alarm! I must have mixed up something in my local testing... We're all good with #5347 now!
Will update this PR accordingly as well.
@mkcor it works! 🎉 No thumbnail though... Is that expected? Also, the 3D dataset gallery page is broken, not sure whether this is specific to this PR or also on master... |
Done dfd9954. Confirming that we can spare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mkcor. This looks good now (I didn't realize this one was still pending!).
One issue I did have when trying it out is that occasionally the Plotly plot would behave strangely when dragging the animation slider (the slider itself sometimes moved to a lower position on the screen mid-drag and the image would quit updating). Hitting the "home" button at top to reset the axes would restore it to a working state again. It might be somehow related to dragging too quickly as I never saw the issue if I just clicked around on different frames, only when dragging the slider. In any case, that seems more likely to be a Plotly issue than an issue with this demo, so I have approved here. I was just curious if you have observed anything similar? I did try in both firefox and chrome and saw the same thing in both.
Thank you for your review, @grlee77! Looking now at the issue you pointed out... Sorry, it's taken me a little while because my local docs build had been broken since #5472; I had to run $ pip install -e . --upgrade --force-reinstall for the changes in |
Without 4cba76b, the Plotly figure wouldn't display anymore, so I have made the script consistent (cf. 2ed4cf9).
Yes! I just reproduced the issue (in Firefox, with my local file). It does seem related to dragging the slider too quickly, indeed, and I was able to reset the expected display/animation by hitting the "home" button as well. |
I think this has waited long enough. 😄 Thanks everyone! |
Description
Hello @sciunto and @emmanuelle !
This PR is an addition to the 3D image processing introduction tutorial, which landed with #4850.
It relates to #4850 (comment) and #4762.
I've made a slice explorer with Plotly so it renders even in the static HTML page.
In future iterations, I'll add a 3D visualization showing the position of the selected slice within the dataset.
I've chosen the density_heatmap function so I could readily use its
animation_frame
argument for the slider interaction (selection). This function is made for aggregation, which I'm bypassing by setting the number of bins to the data size...Ideally, I wanted to use imshow to view the image slices (planes) but this wouldn't offer such a convenient abstraction in terms of slider interaction.
Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.