As I’ve previously in other topic mentioned, I have a vtkResliceCursor, which uses vtkImageData and vtkAlgorithmOutput. Both were provided by vtkDICOMImageReader but it had few flaws. So I’ve decided to generate a 3d numpy array from DICOM images and pass it to vtk.
After generating numpy array (and filling it) with datasets
slice_thickness = datasets.SliceThickness pixels_spacing_0, pixels_spacing_1 = datasets.PixelSpacing ratio = (slice_thinkness/((pixels_spacing_0 + pixels_spacing_1)/2)) numpy_array = np.zeros(( int(len(datasets) * ratio), datasets.pixel_array.shape, datasets.pixel_array.shape ))
I am stumbling on generating vtkImageData with numpy_to_vtk function, because all info on different sites seems kinda different from each other (like reshape numpy array or don’t and etc, flatten or ravel).
I tried to follow one of these examples, but it works not as expected and maybe its because its now missing vtkAlgorigthmOutput which few classes requires
shape = numpy_array.shape if len(shape) < 2: raise Exception('numpy array must have dimensionality of at least 2') h, w = shape, shape c = 1 if len(shape) == 3: c = shape # Reshape 2D image to 1D array suitable for conversion to a # vtkArray with numpy_support.numpy_to_vtk() linear_array = np.reshape(numpy_array, (w*h, c)) vtk_array = numpy_to_vtk(linear_array) self.image = vtkImageData() self.image.SetDimensions(w, h, 1) self.image.GetPointData().SetScalars(vtk_array)
So basically how to get vtkAlgorithmOutput so I can set classes with SetInputConnection(self.algorithm.GetOutputPort())?