问题
I want to resize(downscale) the ground truth 3d images of brain tumor segmentation.
Here are some g.t. + brain images:
G.t. images are 3d numpy array and consist of only 0 and 1 value(only green voxel and black voxel, brain is not included in g.t. image).
def resize(img, shape, mode='nearest', orig_shape=None, order=3):
"""
Wrapper for scipy.ndimage.zoom suited for MRI images.
"""
if orig_shape == None: orig_shape = img.shape
assert len(shape) == 3, "Can not have more than 3 dimensions"
factors = (
shape[0]/orig_shape[0],
shape[1]/orig_shape[1],
shape[2]/orig_shape[2]
)
# Resize to the given shape
return zoom(img, factors, mode=mode, order=order)
# original shape = (150, 512, 512)
# desired shape = (64, 192, 160)
I used scipy zoom, with order 3 and nearest mode. After resizing the images, some of them were ok but some weren't. You can see the problem in the 1st and 2nd images of the above. There are many holes in tumor area which were not there before resizing. The 3rd image doesn't seem to have the issue.
I tinkered some options in zoom function, but didn't find a proper solution. Please help me to solve this. Thank you.
来源:https://stackoverflow.com/questions/61953238/any-recommendation-to-resize-3d-image-array-which-consists-of-only-0-and-1