Example using 3D multichannel image.#4946
Conversation
|
Thanks @mkcor! |
|
Now you understand why it's called confocal fluorescence microscopy!! w00t @GenevieveBuckley ❤️ import plotly.express as px
px.imshow(data[n_plane // 2], zmin=v_min, zmax=v_max)@emmanuelle @nicolaskruchten thanks for making I cannot achieve it with: from skimage import io
io.imshow(data[n_plane // 2], plugin='matplotlib', vmin=v_min, vmax=v_max)import matplotlib.pyplot as plt
plt.imshow(data[n_plane // 2], vmin=v_min, vmax=v_max)It's as if I didn't pass any min/max values... |
|
@mkcor yeah matplotlib's imshow uses |
@emmanuelle yes, I would also prefer double-checking with a specialist of the field if and how we should change the contrast in a fluorescence microscopy image. Notably, should we do it on a per channel basis? I understand that my doing px.imshow(slice, zmin=v_min, zmax=v_max)is equivalent to px.imshow(
slice,
zmin=[v_min, v_min, v_min],
zmax=[v_max, v_max, v_max]
)and, while the maximum value happens to be the same across channels (in this case, px.imshow(
slice,
zmin=[data[:, :, :, 0].min(), data[:, :, :, 1].min(), data[:, :, :, 2].min()],
zmax=[v_max, v_max, v_max]
)doesn't feel great, but maybe it's done...? I would say that px.imshow(
slice,
zmin=[0, 0, 0],
zmax=[v_max, v_max, v_max]
)looks most natural but, again, I'm not familiar enough with confocal fluorescence microscopy. Let's poke some biology experts who might know better! |
Oh, right, the docs read "When using scalar data ..." indeed, but I didn't get that the parameter would just be ignored for multichannel data.
Ok, taking care of it now. |
|
Changing the contrast independently for each channel for visualization is fine. |
|
Great demo! I would also say it's fine to normalize on a per-channel basis and for most cases, it will prevent really poorly scaled images (why is my figure all black/white? questions) and having things just work out of the box is nice. I might have a note of it since many scikit-image tutorials end up as figures in papers (and comparing two groups with normalized channels might lead to wrong conclusions). |
|
@GenevieveBuckley @kmader thank you for your replies, they are really helpful!
@kmader ok, in this case I will favour the following option: px.imshow(
slice,
zmin=[data[:, :, :, 0].min(), data[:, :, :, 1].min(), data[:, :, :, 2].min()],
zmax=[data[:, :, :, 0].max(), data[:, :, :, 1].max(), data[:, :, :, 2].max()]
)
Oh, I would be very interested in this note! Thank you so much, again. |
|
@mkcor Thank you for the poke! Python, bioinformatics... but I am not a biology expert ;-) |
|
@mkcor glad you thought about me! Unfortunately, I have never worked with images so I can't help with this issue! |
|
@fran6w @GMFranceschini I know your expertise is in bioinformatics rather than cell imaging... I reached out just in case and we got answers anyway, so it's all good! Thanks anyway. |
|
Re-posting:
|
jni
left a comment
There was a problem hiding this comment.
@mkcor apologies for the delay in reviewing! This is a great little doc! 😊 I've made two very minor suggestions, but this is ok to merge with or without them. Thank you!
Since this is just a doc change I'll merge in ~24h unless anyone has objections.
| # We turn to `plotly`'s implementation of the `imshow` function, for it | ||
| # supports `value ranges | ||
| # <https://plotly.com/python/imshow/#defining-the-data-range-covered-by-the-color-range-with-zmin-and-zmax>`_ | ||
| # beyond ``(0.0, 1.0)`` for floats and ``(0, 255)`` for integers. |
Co-authored-by: Juan Nunez-Iglesias <[email protected]>
grlee77
left a comment
There was a problem hiding this comment.
Thanks @mkcor, this looks great.
My only question is about how we can make this and other Plotly-based examples more useful for users that try to run them from the command line.
One possibility it calling plotly.io.show on each figure, for example.:
fig = px.imshow(data[n_plane // 2], zmax=vmax)
plotly.io.imshow(fig)If I do that everywhere in the example, I end up with one browser tab per plotly figure. I didn't check if that will interfere with the gallery example, though? Let me know what you think.
Adding a plt.show() at the end of the script can also keep the Matplotlib figure from disappearing immediately once the script completes. We have that in many of the existing Matplotlib-based examples.
I think just |
@grlee77 oh, thanks! 84d65a8 I replaced the entry mentioning a previous biology example (#4648) with this current one, because #4648 made it into the 0.18 release so... I guess it should be pruned from |
|
Hi @grlee77,
Thank you for keeping this in mind! I admit I forgot about this.
or simply (sparing fig = px.imshow(data[n_plane // 2], zmax=vmax)
fig.show()
Right. I think it's quite nice, but...
It does! 😭 I tried and ended up with the same display issue as in: https://scikit-image.org/docs/dev/auto_examples/data/plot_3d.html It used to work, so I'm not sure when the issue arose (maybe a particular mix of Plotly and Sphinx versions...?). I'm noticing a display issue with the thumbnail as well.
Good point. In this gallery example, only one figure (i.e., the first one) is a Matplotlib figure... But it's better than nothing: done 1a0a7af. |
@jni ok, thanks. The overall cleanup could/should be a different PR, so I have pruned only the Documentation section (37b2b07, a0b0de7) by comparing PR should be good to go now! |
|
I opened #5341 about pruning the |
Is there an issue for that? Do you want to open a PR removing the call to show for now so things show up in the gallery as expected? |
Yes, I'll take care of it tomorrow (there's currently no issue for that). |
* Start example using 3D multichannel image * Add plotly as docs dependency * set plotly renderer in conf.py * Update data loading * Visualize image slice with plotly's imshow * Drop deprecated function * Use second plot as thumbnail * Improve code style and wording * Add three interactive visualizations * Tell a better story * Include biological expertise by @GenevieveBuckley * Apply suggestions from code review Co-authored-by: Genevieve Buckley <[email protected]> * Stick with usual convention for 3D spatial coords * Revert "Stick with usual convention for 3D spatial coords" This reverts commit 9656e41. * Name dimensions [plane, row, column, channel] * Apply suggestions from code review Co-authored-by: Juan Nunez-Iglesias <[email protected]> * Add entry to release notes * Keep the Matplotlib figure when running script from CLI * Prune documentation items found in 0.18 release notes * Prune documentation itemequivalent to one found in 0.18 release notes Co-authored-by: Emmanuelle Gouillart <[email protected]> Co-authored-by: Genevieve Buckley <[email protected]> Co-authored-by: Juan Nunez-Iglesias <[email protected]>


Description
I just started a gallery example where I'd like to show possible ways of interacting with 3D multichannel images. I'm using the kidney tissue fluorescence data by @GenevieveBuckley of course. 💞
There's nothing interesting yet. The script does not even run as is, since #4939 isn't merged in yet.
I thought I would dive straight into the 3D challenges, then I realized that rendering the colours wasn't trivial: The image is closer to BGR than it is to RGB, but it's not exactly BGR either... 🙃
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.