Unification ct scan voxel size by using interpolation in Python

后端 未结 2 810
盖世英雄少女心
盖世英雄少女心 2021-01-24 08:29

I have used interp2 in Matlab, such as the following code, that is part of @rayryeng\'s answer in: Three dimensional (3D) matrix interpolation in Matlab:



        
2条回答
  •  攒了一身酷
    2021-01-24 09:32

    In MATLAB, interp2 has as arguments:

    result = interp2(input_x, input_y, input_z, output_x, output_y)
    

    You are using only the latter 3 arguments, the first two are assumed to be input_x = 1:size(input_z,2) and input_y = 1:size(input_z,1).

    In Python, scipy.interpolate.interp2 is quite different: it takes the first 3 input arguments of the MATLAB function, and returns an object that you can call to get interpolated values:

    f = scipy.interpolate.interp2(input_x, input_y, input_z)
    result = f(output_x, output_y)
    

    Following the example from the documentation, I get to something like this:

    from scipy import interpolate
    x = np.arange(0, volume_image.shape[2])
    y = np.arange(0, volume_image.shape[1])
    f = interpolate.interp2d(x, y, volume_image[ind, :, :])
    xnew = np.arange(0, volume_image.shape[2], 1/scaleCoeff[0])
    ynew = np.arange(0, volume_image.shape[1], 1/scaleCoeff[1])
    M2D[ind, :, :] = f(xnew, ynew)
    

    [Code not tested, please let me know if there are errors.]

提交回复
热议问题