scikit-image icon indicating copy to clipboard operation
scikit-image copied to clipboard

Replace `square`, `rectangle`, `cube` with `footprint_rectangular`

Open lagru opened this issue 1 year ago • 5 comments

Description

We have a rework of our footprint generating function on our skimage2 agenda. This WIP starts that work by combining "rectangular" footprint generators (square, rectangle, cube) into a single skimage.morphology.footprint_rectangular with ND support.

This is also an opportunity to change to decomposition="sequence" as the default as suggested in the agenda. Though, I'm not sure if we really want to do this. It's arguably a more unexpected form to represent the footprint for the sake of performance. Usually, we decide that trade-off in favor of simpler behavior.

I plan to do the same for "elliptical" footprint generators in a separate PR to keep reviewing reasonable.

I'm also playing around with a small wrapper class to help with the more complicated representation of decomposed footprints. I might move that into another PR depending on how this approach turns out.

Checklist

Release note

For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.

...

lagru avatar Oct 03 '24 20:10 lagru

I'm thinking how to best go about updating the test suite considering review experience and long-term maintenance.

The test's are somewhat strewn about over at least 2 files. So my idea is to consolidate them in a new Test_footprint_rectangle class but keep the old ones around during the deprecation. That way we make sure that the replacement really fully implements the old API. When we finish the deprecation, we just remove them and are left with a clearer grouping of tests.

lagru avatar Oct 04 '24 15:10 lagru

Have "nd extensions" been using in your "actual work"? I have mostly stayed on "2D" + broadcasting.

I find "square rectangle and cube" relatable, and "footprint_rectangle" just too abstract....

hmaarrfk avatar Oct 04 '24 15:10 hmaarrfk

We are planning on renaming all structuring elements to footprint_, so that part at least will be more obvious.

stefanv avatar Oct 04 '24 20:10 stefanv

My personal gut feeling is that rectangle isn't too abstract for our users to understand that it also entails squares. I could live with keeping footprint_cube as a 3d-specific alias and common use case of the general algorithm in footprint_rectangle around.

But thinking about it more, I'd actually find footprint_rectangular (and footprint_elliptical) to be perfect names. They aren't specific to a number of dimensions and I think communicate the core concept of the footprint class clearly.

Meta: I think the original aim of the discussion was to make our API clearer and reduce the maintenance aspect of it. While working on this, I discovered that the "rectangular" approach can actually be covered by one ND-enabled algorithm. I feel like that one generalized version is actually simpler to maintain long-term.

@hmaarrfk, what do you think?

lagru avatar Oct 10 '24 10:10 lagru

@lagru all green with me.

hmaarrfk avatar Oct 10 '24 15:10 hmaarrfk

pre-commit.ci autofix

jarrodmillman avatar Nov 19 '24 16:11 jarrodmillman

This LGTM. I think the name footprint_rectangle would be clearer, and aligns with previously used names cube, square, etc. This will also help us name the others footprint_diamond, footprint_sphere, etc.

stefanv avatar Nov 28 '24 23:11 stefanv

Hmm, I'm rather fond of "rectangular" which works for any number of dimensions, e.g. rectangular cuboid, square, hyper-cube. footprint_rectangle makes it less clear that this function may also work for more than 2D.

Along the same line of thought, I'd suggest footprint_elliptical for ellipsis, sphere, ball, etc.

I think we only support 2D for diamond, octagon, etc. So going with a more precise name rather than a property makes sense here in my book.

What do you think?

lagru avatar Nov 29 '24 15:11 lagru

I think that's the problem: rectangular means rectangular something, and the name doesn't say what. footprint_hyperrect may have been most correct, and perhaps hyper is a way to distinguish from 2D footprints. Not sure what the correct form of "diamond" would be if we went with "rectangular". Also just extra letters and not the most direct form.

We could also consider footprint_rect_nd, footprint_diamond etc.

stefanv avatar Nov 29 '24 15:11 stefanv

Thanks @mkcor! Do you have a preference or thoughts with regard to footprint_rectangular and footprint_rectangle?

--

I think that's the problem: rectangular means rectangular something, and the name doesn't say what.

@stefanv, I can follow that argument. It may be somewhat alleviated by the fact, that footprint is included in the function name, which identifies the "something".

I still feel like rectangular is the more precise term, but I could live with using _rectangle. In that case, I'd advocate adding footprint_cuboid so that users looking for a 3D option can quickly find it. Then the two most common use cases should be covered.

lagru avatar Dec 01 '24 13:12 lagru

@lagru oh sorry, I'm seeing this conversation only now! I just checked and the second meaning of adjective 'rectangular' is: placed or having parts placed at right angles (so the 'cuboid' case would be covered, in the broad sense).

My personal preference would go to footprint_rect because it's 'safe' and 'inclusive' (may stand for rectangular, rectangle, hyperrect, rect_nd... knowing that our functions are typically nD by default).

mkcor avatar Dec 02 '24 09:12 mkcor

drive by peanut gallery comment (came here from the Scientific Python discord that solicited input here, because who doesn't love a good bike shed?):

I think that's the problem: rectangular means rectangular something, and the name doesn't say what.

In one interpretation, it does: rectangular footprint, where a user can assume you're using a noun_adjective convention to keep all of the nouns together for tab-completion usage and discovery convenience. This then raises the point of what the other footprints will be renamed to. Will it be footprint_sphere or footprint_spherical?

footprint_rect is a nice compromise, practically speaking. You could have a convention of using the 2d projection names for n-dimensional version, but if you stuck to that, would you want to change footprint_sphere to footprint_circle? An the annulus that looks like currently gets called disk - should you keep calling it that in an n-dimensional case, where it should perhaps be better described as a spherical shell?

I really don't have a dog in this race, or a say, but I would leave the "legacy" specialized names, or at least their footprint_ prefixed version to help those that have been using those all along, and cross reference the relevant generalization in their docstrings

Note: footprint_square is a special case of footprint_rect for 2 dimensions having the same size.

This way current users of those functions can continue to use them and think about their problems in the same way, only having to adjust to the footprint_ prefix. You could sprinkle in an optional n_dim or something like that where the hyper-shape makes sense. footprint_cube(3, n_dim=10) is pretty unambiguous, and a more pleasant API than the technically the same footprint_rectangular ((3, 3, 3, 3, 3, 3, 3, 3, 3, 3)), even if you shorten it to footprint_rectangular([3]*10), it's still iffy. I think it would be unergonomic to be forced to use footprint_elliptical to specify hyperspheres, even if that's how they'd be implemented internally.

ivanov avatar Dec 05 '24 03:12 ivanov

leave the "legacy" specialized names, or at least their footprint_ prefixed version to help those that have been using those all along, and cross reference the relevant generalization in their docstrings

That's a good point I hadn't really considered as a deciding factor. Thanks for pointing it out @ivanov. :heart_hands:

Then let's go with footprint_rectangle and the implicit convention of targeting the 2D case when naming footprints. And point out the 1D or ND support in the docstring. Shouldn't be too unexpected for an "image processing lib". :smile:

footprint_cube(3, n_dim=10) is pretty unambiguous, and a more pleasant API than the technically the same footprint_rectangular((3, 3, 3, 3, 3, 3, 3, 3, 3, 3))

We explicitly chose to use an API that works for all shapes consistently, e.g., rectangles or ellipses that can't be represented with the API that you suggest. Another nice perk is, that it's consistent with NumPy's ones, zeros, etc. and rather explicit.

lagru avatar Dec 05 '24 15:12 lagru

@mkcor, footprint_rect would be a way to sidestep this but how would we name the other cases, e.g., ellipsis, circle, sphere, ball? Also, I'm usually not a fan of contractions that may not be as obvious to other people that aren't already familiar with the convention.

lagru avatar Dec 05 '24 15:12 lagru

I'll leave pressing the merge button to one of you, in case we have a consensus. :wink:

lagru avatar Dec 05 '24 15:12 lagru

Thanks all for your inputs!

stefanv avatar Dec 05 '24 16:12 stefanv

By the way, DIPlib uses "rectangular".

lagru avatar Dec 08 '24 14:12 lagru