Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
edited by

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?

1 Answer

0 votes
by (108k points)

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) 

You can refer to the Python Certification for more information regarding the same.

Related questions

0 votes
1 answer
asked Aug 5, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jan 19, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
asked Oct 15, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Oct 3, 2019 in Python by Sammy (47.6k points)

Browse Categories

...