Open paskino opened 2 years ago
I create a numpy array and then save it to disk as TIFF image. For that I use 2 different ways to fractionate the data:
vtkTIFFWriter
Here the data displayed. It is clear that the Y axis is inverted in the 2 images.
Y
I suppose the culprit is in the numpy2vtkImage function.
numpy2vtkImage
The file to produce the dataset is as follows.
import os import unittest import numpy as np import vtk from ccpi.viewer.utils.conversion import (Converter, cilRawResampleReader, cilMetaImageResampleReader, cilNumpyResampleReader, cilNumpyMETAImageWriter, vortexTIFFResampleReader) import warnings bits = 8 shape = (5, 10, 6) size = shape[0] * shape[1] * shape[2] input_3D_array = np.reshape(np.arange(size), newshape=shape)\ .astype(dtype=eval(f"np.uint{bits}")) # Create TIFF Files twriter = vtk.vtkTIFFWriter() vtkfnames = [] pilfnames = [] arr = input_3D_array from PIL import Image for i in range(arr.shape[0]): fname = 'vtk_tiff_test_file_{:03d}.tiff'.format(i) vtkfnames.append(os.path.abspath(fname)) # Using vtk the Y axis gets reversed vtk_image = Converter.numpy2vtkImage(np.expand_dims(arr[i,:,:], axis=0)) twriter.SetFileName(vtkfnames[-1]) twriter.SetInputData(vtk_image) twriter.Write() fname = 'pil_tiff_test_file_{:03d}.tiff'.format(i) pilfnames.append(os.path.abspath(fname)) im = Image.fromarray(arr[i]) im.save(pilfnames[-1])
I think this is relevant / needs sorting out at the same time: https://github.com/vais-ral/CILViewer/issues/196
I create a numpy array and then save it to disk as TIFF image. For that I use 2 different ways to fractionate the data:
vtkTIFFWriter
-> display with imageJHere the data displayed. It is clear that the
Y
axis is inverted in the 2 images.I suppose the culprit is in the
numpy2vtkImage
function.The file to produce the dataset is as follows.