nxnxn matrix python 3, stackoverflow, github

I am currently using a binary array of size 64x64x64, where a volume of 40x40x40 is set as “1” and remaining is “0”. I want to rotate this cube around z-axis with the help of the package named as skimage.transform.rotate and Opencv. The code that I am using is:

def rotateImage(image, angle):

    row, col = image.shape

    center = tuple(np.array([row, col]) / 2)

    rot_mat = cv2.getRotationMatrix2D(center, angle, 1.0)

    new_image = cv2.warpAffine(image, rot_mat, (col, row))

    return new_image

In openCV, I tried, 2D rotation of each slices in a cube like (Cube[:,:,n=1,2,3…p]).

After the implementation of the code, the total sum of the values in the array gets modified. I think this is caused by interpolation during rotation. The main question is that how can I rotate a 3D array of this kind without adding anything to the array?

You can achieve that with the help of the scipy.ndimage package. 

    from scipy.ndimage import interpolation

    angle = 25 #angle should be in degrees

    Rotatedim = interpolation.rotate(your_image, angle, reshape = False,output = np.int32, order = 5,prefilter = False) 

Leave a Comment

Your email address will not be published.