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

rename feret_diameter -> max_feret_diameter ? #4817

Closed
VolkerH opened this issue Jul 2, 2020 · 6 comments · Fixed by #4820
Closed

rename feret_diameter -> max_feret_diameter ? #4817

VolkerH opened this issue Jul 2, 2020 · 6 comments · Fixed by #4820
Labels
🏃 Sprint 💬 Discussion ⚠️ Critical Reserved for newly introduced bugs in a final release

Comments

@VolkerH
Copy link
Contributor

VolkerH commented Jul 2, 2020

Description

Sorry, I meant to comment on this while it was still an open PR, but then forgot to do so.
As it has not been in a release, maybe it is not too late to rename the new region property
feret_diameter to max_feret_diameter.
Tagging @emmanuelle as she added it.

The simple reason being is that sometimes the minimum feret diameter is of interest and
it would be nice to be able to have naming consistency so that a min_feret_diameter property
can get added later.

@jni
Copy link
Member

jni commented Jul 2, 2020

A good point! I'd be 👍 on this. (And yes it's totally fine to change this pre-release.)

@emmanuelle
Copy link
Member

I'm fine with this!

@VolkerH
Copy link
Contributor Author

VolkerH commented Jul 7, 2020

thanks for considering this. Then I need to tidy up the code I have for minimum feret diameter (unfortunately only 2D) next.

Also saw that @maxfrei750 already created a pull request. Not sure whether that'll need rebasing now that the new custom regionprop feature has been merged.

@jni jni closed this as completed in #4820 Jul 14, 2020
@maxfrei750
Copy link
Contributor

@VolkerH

Then I need to tidy up the code I have for minimum feret diameter

Is your code for the minimum Feret diameter already available in scikit-image or somewhere else?

@VolkerH
Copy link
Contributor Author

VolkerH commented Dec 26, 2020

Hi @maxfrei750 ,
sorry for not replying earlier was not on Github much for the last couple of weeks.
No, it isn't in scikit-image yet.
I only have code for 2D min feret diameter, will look for it in the coming days.

@VolkerH
Copy link
Contributor Author

VolkerH commented Jan 12, 2021

@maxfrei750 (apologies for the delay) and others who are interested:

Here is a gist https://gist.github.com/VolkerH/0d07d05d5cb189b56362e8ee41882abf that contains code for calculating minimum feret diameters in the 2D case.

This would still need a bit of tidying before it could go into scikit image and I currently don't have the time. What needs tidying?

  • tests required
  • this code snippet brings its own code to compute upper and lower convex hulls. IIRC correctly, scikit-image uses scipy functions to to compute convex hulls in other places. It would be somewhat redundant to include another implementation of convex hull caclulation just for min feret diameter. OTOH I don't know whether the existing code supports upper and lower convex hulls.
  • it is 2D only. I believe 3D is siginificantly more complex.

I a probably should open a new issue for this, but then I feel I have to work on it.
Pinging @emmanuelle who has worked on the maximum feret diameter code.

ns-rse added a commit to AFM-SPM/TopoStats that referenced this issue Dec 11, 2023
New submodule `measures.feret` with functions for calculation of min and max feret and the associated co-ordinates.

Utilises code from Skan developer see [gist](https://gist.github.com/VolkerH/0d07d05d5cb189b56362e8ee41882abf) and as
[suggested](scikit-image/scikit-image#4817 (comment)) it adds tests. In doing so
I found sorting points prior to calculation of upper and lower convex hulls missed some points.

I'm also not sure about the `rotating_calipers()` function as it doesn't seem to return all pairs formed across the
points from the upper and lower convex hulls and so have included but not used the `all_pairs()` function which does,
although if used in place this doesn't return the minimum feret correctly, rather just the smallest distance.

Currently some of the tests for the `curved_line` fail too.

The intention is to use this without instantiating the `GrainStats` class to be used in profiles (#748) and could serve
as a concise stand-alone set of functions outside of `GrainStats` class which currently has static methods for the
calculations (#750).

Benchmarking

In light of #750 and re-implementing feret calculations as a new sub-module I wanted to see how this compares in terms
of performance to those in `GrainStats()` class so have run some very basic benchmarking. Note this is not the full
pipeline of taking labelled images and finding the outlines/edge points which are required as inputs to the
calculations, its purely on the calculation of min-max feret from the edge points.

```
import timeit

import numpy as np
from skimage import draw

from topostats.measure import feret
from topostats.grainstats import GrainStats

holo_circle = np.zeros((14, 14), dtype=np.uint8)
rr, cc = draw.circle_perimeter(6, 6, 5)
holo_circle[rr, cc] = 1

holo_circle_edge_points = np.argwhere(holo_circle == 1)

%timeit feret.min_max_feret(holo_circle_edge_points)

83 µs ± 686 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

%timeit GrainStats.get_max_min_ferets(holo_circle_edge_points)

1.06 ms ± 10.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
```

So this new implementation is faster.
ns-rse added a commit to AFM-SPM/TopoStats that referenced this issue Dec 11, 2023
New submodule `measures.feret` with functions for calculation of min and max feret and the associated co-ordinates.

Utilises code from Skan developer see [gist](https://gist.github.com/VolkerH/0d07d05d5cb189b56362e8ee41882abf) and as
[suggested](scikit-image/scikit-image#4817 (comment)) it adds tests. In doing so
I found sorting points prior to calculation of upper and lower convex hulls missed some points.

I'm also not sure about the `rotating_calipers()` function as it doesn't seem to return all pairs formed across the
points from the upper and lower convex hulls and so have included but not used the `all_pairs()` function which does,
although if used in place this doesn't return the minimum feret correctly, rather just the smallest distance.

Currently some of the tests for the `curved_line` fail too.

The intention is to use this without instantiating the `GrainStats` class to be used in profiles (#748) and could serve
as a concise stand-alone set of functions outside of `GrainStats` class which currently has static methods for the
calculations (#750).

Benchmarking

In light of #750 and re-implementing feret calculations as a new sub-module I wanted to see how this compares in terms
of performance to those in `GrainStats()` class so have run some very basic benchmarking. Note this is not the full
pipeline of taking labelled images and finding the outlines/edge points which are required as inputs to the
calculations, its purely on the calculation of min-max feret from the edge points.

```
import timeit

import numpy as np
from skimage import draw

from topostats.measure import feret
from topostats.grainstats import GrainStats

holo_circle = np.zeros((14, 14), dtype=np.uint8)
rr, cc = draw.circle_perimeter(6, 6, 5)
holo_circle[rr, cc] = 1

holo_circle_edge_points = np.argwhere(holo_circle == 1)

%timeit feret.min_max_feret(holo_circle_edge_points)

83 µs ± 686 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

%timeit GrainStats.get_max_min_ferets(holo_circle_edge_points)

1.06 ms ± 10.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
```

So this new implementation is faster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏃 Sprint 💬 Discussion ⚠️ Critical Reserved for newly introduced bugs in a final release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants