question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Napari fails to create ellipse when specifying center and radius in 3 dimensions

See original GitHub issue

🐛 Bug

The documentation for creating ellipses states that either the 4 corner vertices must be specified, or a center position and radius must be specified. I find that when attempting to create ellipses the second way, napari throws an error because it expects that the 4 corner method will be used instead. I suspect the issue originates in napari/layers/shapes/_shapes_models/ellipse.py on line 71 where it uses an if statement instead of else if.

To Reproduce

Steps to reproduce the behavior:

  1. Attempt to add an ellipse to a layer in 3 dimensions by specifying a center and radius

Error message:

~/anaconda3/lib/python3.7/site-packages/napari/layers/shapes/_shapes_models/ellipse.py in data(self, data)
     74                     "Data shape does not match a ellipse. Ellipse expects four corner vertices, {number} provided.",
     75                     deferred=True,
---> 76                     number=len(data),
     77                 )
     78             )

ValueError: Data shape does not match a ellipse. Ellipse expects four corner vertices, 2 provided.

Offending code in ellipse.py

@data.setter
    def data(self, data):
        data = np.array(data).astype(float)

        if len(self.dims_order) != data.shape[1]:
            self._dims_order = list(range(data.shape[1]))

        if len(data) == 2 and data.shape[1] == 2:
            data = center_radii_to_corners(data[0], data[1])

        if len(data) != 4:
            raise ValueError(
                trans._(
                    "Data shape does not match a ellipse. Ellipse expects four corner vertices, {number} provided.",
                    deferred=True,
                    number=len(data),
                )
            )

        self._data = data

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Carreaucommented, Mar 25, 2022

I can give it a shot.

On Fri, Mar 25, 2022 at 4:12 PM Nicholas Sofroniew @.***> wrote:

@Carreau https://github.com/Carreau do you want to give implementing something based on #4258 (comment) https://github.com/napari/napari/issues/4258#issuecomment-1073413637 a go?

— Reply to this email directly, view it on GitHub https://github.com/napari/napari/issues/4258#issuecomment-1079125812, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACR5T4WUV5TYTCX4SGCSKTVBXJVXANCNFSM5QW2IEOA . You are receiving this because you were mentioned.Message ID: @.***>

0reactions
Carreaucommented, Mar 29, 2022

We could let the ellipse accept a 2xD array for center/ radii in more than two D. It should actually work almost out of the box as most of the functions I think would work in D dimensions, we just need to update a bunch of doc strings. The ellipse API will then accept either 2xD for center radius or 4xD for corner representation (though now I think about it that should maybe be 2**D x D for the number of corners if all corners are specified …

@Carreau do you want to give implementing something based on #4258 (comment) a go?

For info, most of the 3D rendering of ellipses is completely borked, and render non planar aligned ellipses in wrong orientation and stretching. #4330 should start fixing the rendering.

So I’ve been banging my head as why other representation don’t visually work.

2**D x D for the number of corners if all corners are specified

That should still be (4,D) for ellipses, (2**D, D) would be for D-ellipsoids but I don’t think that should be in the shape layer, should it ? Do we want D-ellipsoids ? or D-shapes in General ?

https://miegakure.com/ and in particular https://www.youtube.com/watch?v=vZp0ETdD37E show some complexities with ND-shapes, and I’m unsure we want to tackle it in napari.

On top of that it would also be unclear to me how to manipulate a 2**D ellipsoid, in particular if the multiple axes are not axis aligned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the shapes layer — napari
Ellipses can be added using either two vectors, one representing the center position of the ellipse and the other representing the radii of...
Read more >
Display text for shapes in 3D - Usage & Issues - Image.sc Forum
I'm trying to follow Annotating segmentation with text and bounding boxes — napari, but it does not do what I expect in my...
Read more >
Python add ellipse - ProgramCreek.com
This page shows Python code examples for add ellipse. ... anticlockwise, in radians asymmetry: float 3rd-order moment for directionality if known kwargs: ...
Read more >
Proceedings of the 21st Python in Science Conference
3. Changes to Python ASDF package. Easier and more flexible mechanism to create new extensions. (2.8.0). The previous system for defining ...
Read more >
3DeeCellTracker, a deep learning-based pipeline for ... - eLife
Despite recent improvements in microscope technologies, segmenting and tracking cells in three-dimensional time-lapse images (3D + T images) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found