Skip to content
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 gallery example for structure_tensor... in 3D! #5012

Merged
merged 18 commits into from
Feb 5, 2021

Conversation

mkcor
Copy link
Member

@mkcor mkcor commented Oct 9, 2020

Description

Addresses part of #4831.
With this PR, I'm following up on #4831 (comment).

@emmanuelle I tried telling a story but, in terms of applications, it's more didactic than scientific.
@GenevieveBuckley I used a small region of the kidney image!

I wanted to include some 3D rendering with Plotly, like:
3d_isotropy
but it would only spit out a JSON:

{'text/html': '<div>            <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG"></script><script type="text/javascript">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}</script>                <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: \'local\'};</script>\n        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>                <div id="de5ac8b7-d7bc-41f1-a094-bc28e8cdaa06" class="plotly-graph-div" style="height:525px; width:100%;"></div>            <script type="text/javascript">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("de5ac8b7-d7bc-41f1-a094-bc28e8cdaa06")) {                    Plotly.newPlot(                        "de5ac8b7-d7bc-41f1-a094-bc28e8cdaa06",                        [{"opacity": 0.5, "slices": {"z": {"locations": [5], "show": true}}, "type": "volume", "value": [774, 566, 384, 333, ...

(plus it would be too heavy).

Checklist

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

@pep8speaks
Copy link

pep8speaks commented Oct 9, 2020

Hello @mkcor! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 199:1: E402 module level import not at top of file

Comment last updated at 2021-01-27 10:25:51 UTC

@mkcor
Copy link
Member Author

mkcor commented Oct 12, 2020

@jni iirc you would recommend these changes: 1a5887b
What's the name for this way of formatting strings again? Thanks!

@jni
Copy link
Member

jni commented Oct 12, 2020

Yes I would and they are f-strings

@alexdesiqueira alexdesiqueira added the 📄 type: Documentation Updates, fixes and additions to documentation label Oct 12, 2020
@mkcor
Copy link
Member Author

mkcor commented Jan 21, 2021

@scikit-image/core please review when you get a chance!

Copy link
Member

@rfezzani rfezzani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mkcor! I just left some minor suggestions 😉

doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
@mkcor
Copy link
Member Author

mkcor commented Jan 22, 2021

@rfezzani thank you for the thorough review!

Copy link
Contributor

@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @mkcor! I have some comments, but think the general approach here is fine and this dataset should be okay to demonstrate the basic principles

doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
doc/examples/applications/plot_3d_structure_tensor.py Outdated Show resolved Hide resolved
coords = np.unravel_index(eigen.argmax(), eigen.shape)
assert coords[0] == 0 # by definition
coords

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to also plot all 3 eigenvalues for a single slice (e.g. 1 subplot per eigenvalue, using uniform brightness scale across subplots).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suggesting a figure something like this, which shows the spatial distribution of the eigenvalues. Do you think it is helpful?

fig, axes = plt.subplots(1, 3)
vmax = eigen[0][coords[1]].max()
axes[0].imshow(eigen[0][coords[1]], vmin=0, vmax=vmax, cmap=plt.cm.viridis)
axes[0].set_title('eigenvalue 0')
axes[1].imshow(eigen[1][coords[1]], vmin=0, vmax=vmax, cmap=plt.cm.viridis)
axes[1].set_title('eigenvalue 1')
axes[2].imshow(eigen[2][coords[1]], vmin=0, vmax=vmax, cmap=plt.cm.viridis)
axes[2].set_title('eigenvalue 2')
for ax in axes:
    ax.set_axis_off()

evs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware I hadn't addressed all of your review comments -- looking now! Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is helpful: It makes it easier to follow the rest of the story. I've added the plot in d82d754. I couldn't resist but use facet_col with plotly's imshow... ❤️ @emmanuelle 😉

Copy link
Contributor

@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mkcor. I am approving this now, but please see one other suggestion regarding potentially showing the eigenvalue images themselves.

@rfezzani
Copy link
Member

rfezzani commented Feb 5, 2021

Thank you @mkcor 🎉.

@rfezzani rfezzani merged commit 6bc7351 into scikit-image:master Feb 5, 2021
@mkcor mkcor deleted the 3d-tensor-example branch April 19, 2021 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📄 type: Documentation Updates, fixes and additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants