Hi I am new to NIFTI data,
Imagine I have a reference plane, In any voxel point I want to make a slice of specific weighted amount. So my slice should align with my reference plane as it should look like my plane translated on that specific voxel position.
import nibabel as nib
import numpy as np
from scipy.spatial.transform import Rotation
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
def rotate_plane_around_point(reference_plane_points, rotation_vector, voxel_coordinates, image_path):
img = nib.load(image_path)
aff_matrix = img.affine[:3, :3]
reference_plane_voxel = np.array(reference_plane_points)
rotation_matrix = Rotation.from_rotvec(rotation_vector).as_matrix()
rotated_plane_voxel = np.dot(rotation_matrix, reference_plane_voxel.T).T
real_world_coordinates = np.dot(aff_matrix, voxel_coordinates)
rotated_plane_real_world = np.dot(aff_matrix, rotated_plane_voxel.T).T
return real_world_coordinates, rotated_plane_real_world
image_path = 'brain_ct.nii'
voxel_coordinates = np.array([-12, -8, 12])
reference_plane_points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
rotation_vector = np.radians([2.4, 0, 0])
real_world_coordinates, rotated_plane_real_world = rotate_plane_around_point(reference_plane_points, rotation_vector, voxel_coordinates, image_path)
Here I got the point in my data to be rotated as my reference plane, but I don't have any idea of how to get the plane.