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

Change in Skeletonisation result with Change in Volume Cropping #75

Closed
ChristianNikolov opened this issue Jul 30, 2022 · 11 comments
Closed

Comments

@ChristianNikolov
Copy link

ChristianNikolov commented Jul 30, 2022

Hello again,

during using Kimimaro I noticed the following inconsistency, which is probably caused by an error I make.

I have a 401x401x401 Volume with a Voxel size of 0.2mm. I segment the structure I need, which is fairly in the middle of the volume. Then I crop the volume so that I reduce the size of the background. However, I noticed that depending on how much of the background I take away with the cropping (with Segmentation i.e. Foreground staying constant), the Skeletonisation result of Kimimaro differs.

In addition, if I leave empty Axial slices, Kimimaro gets confused and the skeletonisation is no longer within the borders of the Foreground/ Segmentation. So in any case I have to crop so that no empty Axial slices are left.

Should I always crop the volume to the borders of the Segmentation in all planes, so that no empty Axial, Frontal and Sagittal slices are left?

Regards

@william-silversmith
Copy link
Contributor

william-silversmith commented Jul 30, 2022 via email

@ChristianNikolov
Copy link
Author

ChristianNikolov commented Jul 30, 2022

Hey Will,

thank you for your answer! I just executed pip install kimimaro -U, the results are unfortunately as before.
Here is the code the way I run it:

import numpy as np
import tifffile
import kimimaro

path = "C:/Users/Christian Nikolov/Desktop/Test/TestFit/TestTight/bina.tif"
img = tifffile.imread(path)

skel = kimimaro.skeletonize(img, teasar_params={'scale': 1, 'const': 25})
skel = skel[list(skel.keys())[0]]

binimg = np.zeros(img.shape)
verts = skel.vertices
print(binimg.shape)
print(verts)
#print(verts.shape)

coordinate = []
for i in range(0, verts.shape[0], 1):
 coordinate = verts[i, :]
 coordinate_tuple = tuple(coordinate)
 coordinate_tuple_int = tuple(map(int, coordinate_tuple))
 binimg[coordinate_tuple_int] = 255

path_out = "C:/Users/Christian Nikolov/Desktop/Test/TestFit/TestTight/Test_1_25.tif"
tifffile.imwrite(path_out, binimg)

For the images, is there a way I can send you the Segmentation (and what file format do you prefer)? I am posting here a Screenshot of the Skeletonisation results of 3 different croppings of the same Segmentation:

image

image

The 1. Skeletonisation from left to right is after a loose cropping, leaving empty slices on all sides; the 2. Skeletonisation is after a cropping that doesn't leave empty axial slices but leaves empty slices on the sides and top of the Segmentation; the 3. Skeletonisation is after a cropping that goes to the Segmentation borders in all planes and doesn't leave empty slices in any plane.

@ChristianNikolov
Copy link
Author

ChristianNikolov commented Jul 31, 2022

!EDIT: I know why the 1. Skeletonisation is faulty, it is not because of Kimimaro. When binarising the Segmentation with ImageJ, if there are empty axial slices they get transformed in foreground. Here is the result when I invert those slices:

image

It now is correctly within the segmentation borders, however it still is slightly different from Skeletonisation 2 and very different from Segmentation 3, while all 3 are from the same Segmentation.

As a comparison, here is the result of the ImageJ 3D Skeletonisation plugin of those 3 Croppings:

image

@william-silversmith
Copy link
Contributor

That's good you figured one of them out. That still looks strange.

If you'd like to send me a data sample, gzipped numpy is a good format if it's small. Else you can apply compresso then compress with gzip to get higher compression of segmentation.

https://github.com/seung-lab/compresso

Please share the cropping code too unless i missed it above.

@ChristianNikolov
Copy link
Author

Hello Will,

I am having some trouble with gzip, can I send you the Segmentation as a .tif? The size of the file is 880 KB.
You can then use the tifffile module to import the .tif file as a 3D numpy array as I do.

import tifffile

path = "C:/Users/Christian Nikolov/Desktop/Test/TestFit/TestLoose/bina_corrected.tif" #for example
img = tifffile.imread(path)

@william-silversmith
Copy link
Contributor

william-silversmith commented Aug 1, 2022 via email

@william-silversmith
Copy link
Contributor

Hi Christian, I took a look at the TIFF files you sent me. I'll run some experiments, but my initial impression is that the reason # 3 is very different is because of the fix_borders parameter which sets targets on all border contacts. Since in # 3 there are many more border contacts than previously in 1 and 2, it stands to reason the skeleton will be pretty different. Try setting fix_borders=False.

The fix_borders argument is there mainly to enable stitching between adjacent skeletons on large datasets. Since you are not doing that, it's not necessary.

@ChristianNikolov
Copy link
Author

Thank you! I see, that makes sence. I'll try setting it to False; otherwise I can just leave some space to the segmentation borders as in #1 and #2.

@ChristianNikolov
Copy link
Author

Eurica! Here are the 3 Croppings with fix_borders = False

image

I have to still test it but they seem pretty similar to me : )

@william-silversmith
Copy link
Contributor

william-silversmith commented Aug 1, 2022 via email

@william-silversmith
Copy link
Contributor

william-silversmith commented Oct 11, 2022 via email

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

No branches or pull requests

2 participants