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

[WIP] Get maximum branch #101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

snowformatics
Copy link

Trying to implement a maximum branch method. Currently not working but with questions as comments .

Copy link
Owner

@jni jni left a comment

Choose a reason for hiding this comment

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

@snowformatics thanks for this PR! I've made some comments that I hope will help you get a bit further in!

skan/csr.py Outdated
The maximum length in the skeleton.
"""

sums = np.maximum.reduceat(self.paths.data, self.paths.indptr[:-1])
Copy link
Owner

Choose a reason for hiding this comment

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

This should be called maxes, obviously. ;)

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I still don't get what you mean :( Do you mean the ufunc maximum? Or the docstring naming?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Juan means that he would prefer the variable sums instead be called maxes (because it was arrived at using the numpy maximum function, I imagine)

Copy link
Author

Choose a reason for hiding this comment

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

Ok thanks, I missunderstood.

# 11-14 --> [1. 1. 1. ] --> maximum --> 1.
# 14-17 --> [1. 1. 1. ] --> maximum --> 1.
# 17: --> [1. 1. 1. 1.] --> maximum --> 1.
# which will end up with sums = [1. 1. 1. 1.]
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, so the problem is that the test data is not "interesting" enough for this problem. To make it more interesting, you should change the test data to be e.g. random numbers. Or whatever, like a pyramid, [1, 2, 1], [1, 2, 2, 1], [1, 2, 3, 2, 1]...?

Then, you can just return the maxes! We are only after the maximum value, right?

The key is that when you replace the values of the skeleton by the distance transform, rather than just 1s, getting the max will tell you the maximum width of the skeleton at each branch.

On the other hand, maybe what you want is the minimum width? Or the width at the midpoint of the branch? If you think about how a skeleton image tends to look, the junctions are almost always farther away from the edge of the object than the middle of the branches.

Sorry, I'm about to hop in bed, I hope that this makes sense, if not I will try to draw a diagram tomorrow, sometimes text is not enough. 😊

Copy link
Author

Choose a reason for hiding this comment

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

I see, I will try and come back again :) Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jni perhaps you should try and clarify this (@snowformatics did say below they aren't sure how to follow your testing suggestions). This'll be the most important next step to unstick this PR

print (csr.path_maximum_length())
print (stats)
#print (stats.loc[0, 'max-length'], expected)
#assert_almost_equal(stats.loc[0, 'max-length'], expected)
Copy link
Owner

Choose a reason for hiding this comment

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

As above: you need to make a slightly more interesting test case for this, just by varying the values inside the skeleton.

skan/csr.py Outdated Show resolved Hide resolved
skan/test/test_csr.py Outdated Show resolved Hide resolved
@mkcor
Copy link
Collaborator

mkcor commented Jul 17, 2021

Hi @snowformatics,

Are you still working on this by any chance? 😃

@snowformatics
Copy link
Author

snowformatics commented Jul 17, 2021

Hi @snowformatics,

Are you still working on this by any chance? 😃

Hi @mkcor ,

unfortunately not but would be still interested to work on it with some support. I was kind of stucked (my first PR)

Cheers

@mkcor
Copy link
Collaborator

mkcor commented Jul 17, 2021

unfortunately not but would be still interested to work on it with some support. I was kind of stucked (my first PR)

Great! How can I help you?

  • Do you need help with Git?
  • Are you able to resolve the current conflict in file skan/csr.py?
  • Are you able to apply suggested changes?
  • Are you able to follow the testing suggestions made by @jni?

snowformatics and others added 2 commits July 26, 2021 08:01
Co-authored-by: Marianne Corvellec <[email protected]>
Co-authored-by: Marianne Corvellec <[email protected]>
@snowformatics
Copy link
Author

unfortunately not but would be still interested to work on it with some support. I was kind of stucked (my first PR)

Great! How can I help you?

  • [N] Do you need help with Git?
  • [N] Are you able to resolve the current conflict in file skan/csr.py?
  • [Y] Are you able to apply suggested changes?
  • [N] Are you able to follow the testing suggestions made by @jni?

Help would be great, thanks a lot!

@mkcor
Copy link
Collaborator

mkcor commented Jul 26, 2021

Hi @snowformatics,

[N] Are you able to resolve the current conflict in file skan/csr.py?

Either use the online editor (by clicking the "Resolve conflicts" button in this page), or use your own editor locally (after merging current master into your feature branch). In either case, you'll see the conflict highlighted as follows:

conflict

Basically, Git needs to know which changes you want to include exactly. Unless you want to use pad in this PR (but it looks like you're not using it), you want to go for the version that currently lives on master. So you want to edit out 4 lines:

  • the one with <<<<<<<,
  • the one with >>>>>>>,
  • the one with =======,
  • as well as from .nputil import pad, raveled_steps_to_neighbors

Once you are done (file looks the way you intend), commit and you're done! If you were editing online, don't forget to pull, and if you were working locally, don't forget to push this update.

@snowformatics
Copy link
Author

snowformatics commented Jul 28, 2021

Hi @snowformatics,

[N] Are you able to resolve the current conflict in file skan/csr.py?

Either use the online editor (by clicking the "Resolve conflicts" button in this page), or use your own editor locally (after merging current master into your feature branch). In either case, you'll see the conflict highlighted as follows:

conflict

Basically, Git needs to know which changes you want to include exactly. Unless you want to use pad in this PR (but it looks like you're not using it), you want to go for the version that currently lives on master. So you want to edit out 4 lines:

  • the one with <<<<<<<,
  • the one with >>>>>>>,
  • the one with =======,
  • as well as from .nputil import pad, raveled_steps_to_neighbors

Once you are done (file looks the way you intend), commit and you're done! If you were editing online, don't forget to pull, and if you were working locally, don't forget to push this update.

This was very helpful, thanks for your patience! I hope it's correct now.

@mkcor
Copy link
Collaborator

mkcor commented Jul 28, 2021

Great job, @snowformatics! You're welcome.

As per testing, I can see that you started with a 1D image:

image = np.random.random((45,))

Following https://jni.github.io/skan/getting_started.html#extracting-a-skeleton-from-an-image, do I understand correctly:

  • you threshold at 0.5 to binarize the 1D image;
  • you get a series of blocks of various lengths;
  • the 'maximum path length' in this case is the max of all block lengths

?

I think that a 2D toy example would be nice as well, so we can view it with imshow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants