Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

map(float for Resampling DICOM images throwing Multivalue error

I am getting "can only concatenate list (not "MultiValue") to list" highlighting map (float portion, while running below resampling, this code is very commonly used throughout image segmentation like lungs etc, I am thinking maybe this is issue with Python 3 and was working for earlier versions, any help is much appreciated:

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)
like image 430
1369 Avatar asked Apr 23 '18 02:04

1369


1 Answers

Change

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

To

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

Basically scan[0].PixelSpacing is a MultiValue and need to be converted into list before concatenation to another list.

like image 180
Ankur Avatar answered Oct 17 '22 23:10

Ankur