-
Notifications
You must be signed in to change notification settings - Fork 14
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
add skeletonization code #65
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 40 45 +5
Lines 1411 1545 +134
======================================
- Misses 1411 1545 +134 ☔ View full report in Codecov by Sentry. |
@@ -0,0 +1,77 @@ | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this function? Could be replaced by torch Gaussian filtering, I think? This should be even faster when running on GPU.
from scipy.fftpack import fftn, fftshift, ifftn | ||
|
||
|
||
def angauss(T: np.ndarray, std: float, r: float) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this is a function from Antonio's PySeg. Please make sure to add a note to all of these functions that they come from Antonio's repo :)
Nx, Ny, Nz = T.shape | ||
|
||
# Initialize arrays for forward and backward differences | ||
Idp = np.zeros((Nx, Ny, Nz), dtype="float64") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make these variable names a bit more descriptive? Would make it easier to read the function
from skimage.util import img_as_float32 | ||
|
||
|
||
def read_nifti(nifti_file: str) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have all of these functions in
https://github.com/teamtomo/membrain-seg/blob/main/src/membrain_seg/segmentation/dataloading/data_utils.py
Please use these instead of defining them again here :)
This command runs the skeletonization process from the command line. | ||
""" | ||
# labels can be .nii files or mrc files | ||
if label_path.endswith(".nii") or label_path.endswith(".nii.gz"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can neglect the case of nifti files here. Let's just keep the mrc files.
Also, let's not check for file endings here because there are multiple valid file extensions that work in a similar way and can be processed out-of-the-box by the "load_tomogram" function (e.g. .mrc, .rec, .em, ...).
|
||
# Segmentation consists of 0, 1 and 2 respectively | ||
# for background, mask and labels to be ignored. | ||
labels = (segmentation == 1) * 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normally, we will not have the case that we have ignore labels (that's just for the training patches).
So maybe we can make this criterion (segmentation > 0) * 1.0
This will account also for multiple instance values
hessianZZ = angauss(hessianZZ, std, 1) | ||
hessianXY = angauss(hessianXY, std, 1) | ||
hessianXZ = angauss(hessianXZ, std, 1) | ||
hessianYZ = angauss(hessianYZ, std, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please factor out the hessian computation into a separate function?
I.e. a function that computes the gradients, the hessian, and then smoothes the hessian?
print("Genration of skeleton based on non-maximum suppression algorithm.") | ||
first_eigenvalue = ndimage.gaussian_filter(first_eigenvalue, sigma=1) | ||
first_eigenvalue = np.abs(first_eigenvalue) | ||
Skeleton = nonmaxsup( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capitalized variable names indicate classes, so better call it "skeleton" instead of "Skeleton"
) | ||
|
||
# Save the skeleton | ||
write_nifti(save_path, Skeleton) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default output should be an .mrc file. Please use
def normalize_tomogram(tomogram: np.ndarray) -> np.ndarray: |
Thanks a lot for the updates @Hanyi11 |
No description provided.