I'm trying to load a NIFTI image in vtk using python. The data is already load using nibabel, and I can visualize it with a pyplot (1 slice per plot, my data is a ndarray). But I want to load it has an ImagePlaneWidget ... something like this.
I can't load the data like imageplanewidget wants (vtkDataSet)... How can I do that?
import nibabel as nib
import matplotlib.pyplot as plt
import vtk
img = nib.load('image.nii.gz')
img_data = img.get_data()
print img_data.shape
def show_slices(slices):
fig,axes = plt.subplots(1, len(slices))
for i, slice in enumerate(slices):
axes[i].imshow(slice.T, cmap="gray", origin="lower")
slice_0=img_data[100, :, :]
slice_1=img_data[:, 100, :]
slice_2=img_data[:, :, 100]
show_slices([slice_0, slice_1, slice_2])
plt.suptitle("Image")
plt.show()
plane = vtk.vtkImagePlaneWidget()
plane.SetInputData(img_data)
Thanks a lot, I'm newbie in python and vtk
You have two possibilities: