Accelerate MRI slicing python

Viewed 42

I am new to the programming world and I'm trying to develop a script in python (and PyQt) that does MRI slicing. I am using Pyvista to slice and display MRI images. The problem is that slicing takes too long when I'm using Pyvista, and this is how I am doing it: all_slices_x = mesh.slice_along_axis(n= numberOfSlices, axis='x') Since numberOfSlices is kind of a big number (in the hundreds) it's taking too much time to finish. I do the same thing for all 3 axes. Is there any way I can speed up the slicing process? Here's an extract from the code:

class NIFTIReader(BaseReader):
    _class_reader = vtkNIFTIImageReader
        
#convert nifti to vtk
reader = NIFTIReader(filename)

#plot design
plotter.set_background("white")
plotter.show_axes()

#read vtk file
mesh = reader.read()

#return (xmin, xmax, ymin, ymax, zmin, zmax) of the dataset
Bounds = mesh.bounds
maxX = int(Bounds[1]) #194
maxY = int(Bounds[3]) #239
maxZ = int(Bounds[5]) #175

#start timer just before slicing
start_time = time()

#create many slices of the input dataset along a all axes
slicesx = mesh.slice_along_axis(n= maxX-1, axis='x')
slicesy = mesh.slice_along_axis(n= maxY-1, axis='y')
slicesz = mesh.slice_along_axis(n= maxZ-1, axis='z')

#check how much time it took to slice data
print("--- %s seconds ---" % (time() - start_time)) # result: --- 839.4215893745422 seconds ---

#display the middle slice along the x axis
plotter.add_mesh(slicesx[maxX//2], cmap = "gray", show_scalar_bar=False, lighting = True)

Thank you guys!

0 Answers
Related