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

Allow specifying a root position of the tree #95

Open
RomStriker opened this issue Jan 21, 2025 · 7 comments
Open

Allow specifying a root position of the tree #95

RomStriker opened this issue Jan 21, 2025 · 7 comments
Labels
feature New feature or request

Comments

@RomStriker
Copy link

Hi William,

I am using Kimimaro, to generate centerline graphs for the Parse 2022 challenge dataset. It works well, however, the selected starting or root point is usually incorrect and leads to an incorrect graph. It would be great if we could provide the root point position. I see that there is an old open issue by you that maybe mentions this. Was this ever implemented? You can see an example of the issue below, the larger red marker shows the chosen root point.

Image

Thank you for your amazing work.

@RomStriker
Copy link
Author

Never mind, I see that I can pass an argument for it.

@william-silversmith
Copy link
Contributor

Hi! Yes, there is that burried option in trace.py, but you do have to do some other steps manually to use it. To what degree though would your issues be solved by a rotation of the final skeleton?

@william-silversmith william-silversmith added the feature New feature or request label Jan 21, 2025
@RomStriker
Copy link
Author

RomStriker commented Jan 22, 2025

What do you mean by rotation of the final skeleton? I would prefer fixing the root point as I have that information.

Regarding the root point, what steps do I need to take? I tried to pass it with Teaser parameters as below.

skels = kimimaro.skeletonize(
        mask,
        teasar_params={
            "scale": scale,
            "const": 2 * voxel_res,  # physical units
            "pdrf_scale": 100000,
            "pdrf_exponent": 4,
            "soma_acceptance_threshold": 10000,  # physical units
            "soma_detection_threshold": 10000,  # physical units
            "soma_invalidation_const": 300,  # physical units
            "soma_invalidation_scale": 2,
            "max_paths": 10000,  # default None
            "root": root_position,  # default None
        },
        # object_ids=[ ... ], # process only the specified labels
        # extra_targets_before=[ (27,33,100), (44,45,46) ], # target points in voxels
        # extra_targets_after=[ (27,33,100), (44,45,46) ], # target points in voxels
        dust_threshold=200 * voxel_res,  # skip connected components with fewer than this many voxels
        anisotropy=(voxel_res, voxel_res, voxel_res),  # default True
        fix_branching=True,  # default True
        fix_borders=True,  # default True
        fill_holes=False,  # default False
        fix_avocados=False,  # default False
        progress=True,  # default False, show progress bar
        parallel=0,  # <= 0 all cpu, 1 single process, 2+ multiprocess
        parallel_chunk_size=100,  # how many skeletons to process before updating progress bar
    )

I also commented out the line so the trace function gets the root position.

Now the algorithm just keeps running for a long time. Looking a bit deeper, I see that dijkstra3d.railroad keep returning empty lists. To fix the issue, I set fix_bracnhing to False, but then I get the following error.

File "/home/roman/anaconda3/envs/clf-t220c118/lib/python3.10/site-packages/kimimaro/trace.py", line 155, in trace
    parents = dijkstra3d.parental_field(PDRF, root, voxel_graph)
  File "dijkstra3d.pyx", line 581, in dijkstra3d.parental_field
ValueError: Only 6, 18, and 26 connectivities are supported. Got: None

Any help would be appreciated.

@william-silversmith
Copy link
Contributor

What do you mean by rotation of the final skeleton? I would prefer fixing the root point as I have that information.

If the final skeleton includes the root point, I think you could do a "tree rotation" to put your favored point at the root of the skeleton. It's probably something I should include in the skeleton package. However, if your point isn't in the final skeleton then yes, you need to trace from that point.

To fix the issue, I set fix_branching to False, but then I get the following error.

This issue is now fixed on master per #93 I'm working on a new release, something is breaking in testing that is probably unrelated.

Regarding the root point, what steps do I need to take? I tried to pass it with Teaser parameters as below.

Currently, there is no official way to pick your own root. I'll have to add this feature.

@RomStriker
Copy link
Author

If the final skeleton includes the root point, I think you could do a "tree rotation" to put your favored point at the root of the skeleton. It's probably something I should include in the skeleton package.

Let's say that my favored root point is included in the final skeleton as shown in the below screenshot. Will this tree rotation, recreate the skeleton, by tracing from the favored root point? That is important because I would like to fix the major bifurcation marked in the screenshot.

Image

@RomStriker RomStriker reopened this Jan 23, 2025
@william-silversmith
Copy link
Contributor

Ok, I see what you're trying to do now. No, a rotation will not fix this. I thought you just wanted to organize your skeleton a bit differently, not change the structure.

I think you can eliminate that spurious tail with either increasing scale or const, but the direction of the fork will not rotate without changing the direction of the trace. One thing you could try is setting the soma parameters more aggressively to try to automatically pick root in that thick region. Otherwise, you'll have to modify the code to allow for picking a root.

@RomStriker
Copy link
Author

RomStriker commented Jan 23, 2025

I adjusted the soma parameters which fixes the root issue in some cases. I ended up replacing the detected soma with my root position and got the desired result.

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

No branches or pull requests

2 participants