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

General Question: How to use simple merge to merge skel_ids spread across different folders? #92

Open
Mohinta2892 opened this issue Dec 5, 2024 · 3 comments
Labels
question Further information is requested

Comments

@Mohinta2892
Copy link

Hello!

I have written a tiny snippet as below to merge skels of the same label id that are spread across many folders. However, after merge when I visualise it, no skeleton gets plotted. The final file contains data as attached.

I wanted to know what I am doing incorrectly and get your feedback if this is how simple_merge is to be used?

output_skels = “/path/to/out_skels"
## read skel files for the same label id
skels_to_merge = [('27049069.swc',
                   ‘/path1/27049069.swc|/path2/27049069.swc|/path3/27049069.swc|/path4/27049069.swc')]

for i, files in enumerate(skels_to_merge):
    filename = files[0]
    filepaths = files[1].split('|')
    basename, ext = os.path.splitext(filename)
    skels_list = []
    for fp in filepaths:
        if ext == ".swc":
            with open(fp, "rt") as swc:
                skel = Skeleton.from_swc(swc.read())
                skels_list.append(skel)
                # skel.viewer()

    skel = Skeleton.simple_merge(skels_list).consolidate()
    skel = kimimaro.postprocess(
        skel,
        dust_threshold=1000,  # physical units
        tick_threshold=3500  # physical units
    )
    # print(skel)
    fname = f"{output_skels}/{filename}"
    with open(fname, "wt") as f:
        f.write(skel.to_swc())

27049069.swc.zip

Thank you,
Samia

@william-silversmith
Copy link
Contributor

Hi Samia!

When I open your file, I get the following result. I see something similar in SharkViewer. Is this not what you were expecting? Can you show how you are visualizing the data?

image of skeleton with two connected components colored by radius to boundary

@william-silversmith william-silversmith added the question Further information is requested label Dec 5, 2024
@Mohinta2892
Copy link
Author

Many thanks William.

I can visualise it in SharkViewer. However, when I do kimimaro view /path/to/skeleton.swc, nothing gets plotted.

Kimimaro version: 4.1.2

Figure_1

Also, I was hoping the skeletons to be connected as one object. This is something that simple_merge should achieve right?

@william-silversmith
Copy link
Contributor

william-silversmith commented Dec 6, 2024

Huh, this is pretty strange. I tried using the CLI and I got the same image I got above. Try updating pip install cloud-volume matplotlib -U? I think there was a breaking change at some point.

Yes, simple_merge should combine them all into one object. All it does is staple them together. So if they are not showing up as a single object, either the input is wrong or the postprocessing is too aggressive. For example, if there is a broken link, then the dust threshold could remove segments.

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

No branches or pull requests

2 participants