Created
January 5, 2022 09:34
-
-
Save caniko/d699dc280a478ca06c6710e39a8202e0 to your computer and use it in GitHub Desktop.
Implementation of morphological interpolation along the z-axis for binarized images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
import itk | |
import numpy as np | |
from yaspin import yaspin | |
from yaspin.spinners import Spinners | |
INTERPOLATION_TEXT = "Interpolating for the first time" | |
@yaspin(Spinners.bouncingBall, text=INTERPOLATION_TEXT) | |
def morphological_interpolation( | |
labeled_stack: np.ndarray, stack_depth_spacing: Union[float, int] | |
): | |
spacing_array = np.zeros( | |
(round(stack_depth_spacing), *labeled_stack.shape[1:]), | |
dtype=labeled_stack.dtype, | |
) | |
spaced_stack = [] | |
for xy_plane in labeled_stack: | |
spaced_stack.append(np.expand_dims(xy_plane, axis=0)) | |
spaced_stack.append(spacing_array) | |
spaced_stack.pop(-1) | |
spaced_stack = np.concatenate(spaced_stack) | |
spaced_stack.astype(labeled_stack.dtype, copy=False) | |
return itk.GetArrayFromImage( | |
itk.morphological_contour_interpolator(itk.GetImageFromArray(spaced_stack)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment