在 python 中重新采样体积图像数据

问题描述 投票:0回答:1

我有代表人类乳房 3D 扫描的体积数据,体素大小为(0.2 毫米、0.073 毫米、0.47 毫米)。我需要对这些数据重新采样,以便所有体素大小都相同。是否有可用于插值重采样的 Python 函数?

或者,我希望编写一个自定义函数来实现以下目标:

volume, mask, label = dataset[0]

def resample_volume(volume, pixel_sizes={'x': 0.2, 'y': 0.073, 'z': 0.475}):
    # Implementation goes here
    return resampled_volume
python numpy scipy
1个回答
0
投票

我发现有两种选择:

  1. scipy.ndimage.zoom
def resample(x, pixel_sizes = {'x': 0.2, 'y': 0.073, 'z': 0.475674}):

    # Determine the smallest pixel size
    smallest_pixel_size = min(pixel_sizes.values())
    # Calculate the scaling factors
    scaling_factors = {dim: pixel_sizes[dim] / smallest_pixel_size for dim in pixel_sizes}
    # Resample the dataset using zoom function from scipy
    return zoom(x, zoom=[scaling_factors['x'], scaling_factors['y'], scaling_factors['z']], mode='nearest')
  1. scipy.interpolate.RegularGridInterpolator
def resample_volume(volume, pixel_sizes={'x': 0.2, 'y': 0.073, 'z': 0.475}):
    steps = list(pixel_sizes.values())    # original step sizes
    x, y, z = [steps[k] * np.arange(volume.shape[k]) for k in range(3)]  # original grid
    f = RegularGridInterpolator((x, y, z), volume)    # interpolator
    step = min(steps)
    dx, dy, dz = [step for i in range(3)]   # new step sizes
    new_grid = np.mgrid[0:x[-1]:dx, 0:y[-1]:dy, 0:z[-1]:dz]   # new grid
    new_grid = np.moveaxis(new_grid, (0, 1, 2, 3), (3, 0, 1, 2))  # reorder axes for evaluation
    return f(new_grid)

第二种方法对于图像掩模产生的结果不令人满意。下图分别说明了使用

zoom
RegularGridInterpolator
获得的结果:

enter image description here

enter image description here

现在的问题是,有没有更好的解决方案?

© www.soinside.com 2019 - 2024. All rights reserved.