5

我得到“只能将列表(不是“多值”)连接到列表”突出显示图(浮动部分,在重采样下运行时,此代码在整个图像分割中非常常用,如肺等,我想这可能是 Python 的问题3 并且正在为早期版本工作,非常感谢任何帮助:

id = 0
imgs_to_process = 
np.load(output_path+'fullimages_{}.npy'.format(id))
def resample(image, scan, new_spacing=[1,1,1]):
    # Determine current pixel spacing
    spacing = map(float, ([scan[0].SliceThickness] + scan[0].PixelSpacing))
    spacing = np.array(list(spacing))

    resize_factor = spacing / new_spacing
    new_real_shape = image.shape * resize_factor
    new_shape = np.round(new_real_shape)
    real_resize_factor = new_shape / image.shape
    new_spacing = spacing / real_resize_factor

    image = scipy.ndimage.interpolation.zoom(image, real_resize_factor)

    return image, new_spacing

print ("Shape before resampling\t", imgs_to_process.shape)
imgs_after_resamp, spacing = resample(imgs_to_process, patient, [1,1,1])
print ("Shape after resampling\t", imgs_after_resamp.shape)
4

3 回答 3

10

改变

spacing = map(float, ([scan[0].SliceThickness] + scan[0].PixelSpacing))

spacing = map(float, ([scan[0].SliceThickness] + list(scan[0].PixelSpacing)))

基本上 scan[0].PixelSpacing 是一个 MultiValue 并且需要在连接到另一个列表之前转换为列表。

于 2018-05-09T17:08:41.217 回答
0

这是解决方案:

def resample(image, scan, new_spacing=[1,1,1]):
    # Determine current pixel spacing
    spacing = [scan[0].SliceThickness]
    spacing.extend(scan[0].PixelSpacing)
    spacing = np.array(spacing, dtype=np.float32)
    
    resize_factor = spacing / new_spacing
    new_real_shape = image.shape * resize_factor
    new_shape = np.round(new_real_shape)
    real_resize_factor = new_shape / image.shape
    new_spacing = spacing / real_resize_factor
    
    image = scipy.ndimage.interpolation.zoom(image, real_resize_factor)
    
    return image, new_spacing
于 2022-01-28T11:25:31.933 回答
0

这是修复:

def resample(image, scan, new_spacing=[1,1,1]):
    spacing = np.array([float(scan[0].SliceThickness)] + [float(x) for x in scan[0].PixelSpacing], dtype=np.float32)
    resize_factor = spacing / new_spacing
    new_real_shape = image.shape * resize_factor
    new_shape = np.round(new_real_shape)
    real_resize_factor = new_shape / image.shape
    new_spacing = spacing / real_resize_factor
    image = scipy.ndimage.interpolation.zoom(image, real_resize_factor, mode='nearest')
    return image, new_spacing

pix_resampled, spacing = resample(first_patient_pixels, first_patient, [1,1,1])
print("Shape before resampling\t", first_patient_pixels.shape)
print("Shape after resampling\t", pix_resampled.shape)

基本上,制作 scan[0].SliceThickness以及scan[0].PixelSpacing

“浮动”值的“列表”。

于 2020-09-18T19:26:06.893 回答