Hello!
I want to convert png to vti.
However, the following code does not work correctly.
import os
import cv2
import numpy as np
import pydicom
import matplotlib.pylab as pltfrom glob import glob
def dividePath(dataPath):
imgFileList =for idx, name in enumerate(dataPath): imgFileList.append(name) imgFileList.sort() return imgFileListdef imageLoad(imageFileName):
firstImage = cv2.imread(os.path.join(path, imageFileName[0]))if len(firstImage.shape) == 2: imgRows, imgCols = firstImage.shape[:2] imageList = np.zeros((len(imageFileName), imgRows, imgCols, 1)) else: imgRows, imgCols, imgColor = firstImage.shape[:3] imageList = np.zeros((len(imageFileName), imgRows, imgCols, imgColor)) for idx, fileName in enumerate(imageFileName): imageData = cv2.imread(os.path.join(path, fileName)) copyImageData = imageData.copy() imageList[idx, :, :, :] = copyImageData #print(imageList.shape) return imageListglobal path
global dataPath
path = “C:/JLKINSPECTION_NUC/Material/PNG/patient002_image”
dataPath = os.listdir(path)imageFileList= dividePath(dataPath)
imageList = imageLoad(imageFileList)
print(imageList)from pyevtk.hl import imageToVTK
imageToVTK(“./brainResult8”, pointData={“DICOMImages” : imageList})
However, the following error occurs.
"Bad array shape: " + str(data.shape)
I think there is a problem with png’s data array to convert to vti. But I can’t find a solution.
Can anyone tell me if I know about this?

