r/learnpython • • Jun 27 '24

3D Rotation

Hello all,

I am trying to do a rotation about the x-axis. I'm finished with the code, but trying to find an alternative that could reduce the computation timing. I have almost 200 images and it took me about 1 hour to calculate them. Yes, it is a lot, but I need them for analysis and this is the least number of images that I could get (some of them have more than 300 images).

I included the function code here. Any suggestions?

Thanks

def rotate_G(mask, Angle):
    
     # Stack all rows together into a 3D array
     mask_xyz = np.repeat(mask[:, :, np.newaxis], max(mask.shape[0], mask.shape[1]), axis=2)
    
     # Rotate all rows at once around x-axis
     rotated_mask = rotate(mask_xyz, -Angle, axes=(1,2), reshape=False, order=1)
    
     # Extract the midline
     mid_z = rotated_mask.shape[2] // 2
     midline_z = rotated_mask[:, :, mid_z]
    
     # Convert to array
     projected_mask = np.array(midline_z)
    
     return projected_mask
1 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/Disastrous-Team-6431 Jun 29 '24

Could you not do this in an actual 3d gfx lib? Like, make a texture out of your image and actually rotate it?

1

u/slittyslit Jun 29 '24

Never heard that lib before. Can that store data on every lib though? In my case, I store the light intensity and its angle for each pixel.

1

u/Disastrous-Team-6431 Jun 29 '24

I still don't understand what you're doing or why, but it all sounds like there exists matrix theory and/or libraries to do it. I've gathered that you want to manipulate pixel data - that is one of the most well studied things you can do with a computer.

1

u/slittyslit Jun 29 '24

Just checked it, and nope that won't work in my case