Click here to Skip to main content
16,020,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

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.

What I have tried:

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)

If I am not clear, please tell me so that I can explain more, this is my first time asking a question in here and I'm a beginner so bare with me.
Thank you guys!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900