I am working with 3D CT images and trying to resize the binary segmentation mask from (564,359,359) into (128,128,128) as follows:
from skimage.transform import resize
mask_resized= resize(binary_mask, (128, 128, 128), order=0)
Binary mask before resizing looks as follows:
The resulting output is not binary (yields a series of values between 0 & 1) and the output is distorted as follows:
I tried image_resized_seg = np.rint(image_resized_seg), but this yields full black images for some slices containing the segmentation mask.
I tried the following as well, which also gives distorted images and some slices containing mask is missing in the output:
from scipy import ndimage
def resize_volume_mask(img):
"""Resize across z-axis"""
# Set the desired depth
desired_depth = 128
desired_width = 128
desired_height = 128
# Get current depth
current_depth = img.shape[0] #-1
current_width = img.shape[1] #0
current_height = img.shape[2] #1
# Compute depth factor
depth = current_depth / desired_depth
width = current_width / desired_width
height = current_height / desired_height
depth_factor = 1 / depth
width_factor = 1 / width
height_factor = 1 / height
# Rotate
#img = ndimage.rotate(img, 90, reshape=False)
# Resize across z-axis
img = ndimage.zoom(img, (depth_factor, width_factor, height_factor), order=0)
return img
Could someone please advise on how to resize the segmentation mask without loss of information, while keeping it binary?
from How to resize an image in python using skimage?


No comments:
Post a Comment