Hello, I’ve been working on writing a code to read in Seiman’s format PET and CT scans, and I’ve got the majority of the code written. Currently, it reads in PET images with no issues, and I can adjust and view them. However, when I try to load in a CT data set, which is much larger (496x496x496 as opposed to 128x128x159), A couple lines in the code cause my program to crash.
I load in the file as a numpy array and then use a slightly adjusted code I found in the forums by Csaba, which I’ll paste below:
importer = vtk.vtkImageImport()
importer.CopyImportVoidPointer(img, img.nbytes) setDataType = 'importer.SetDataScalarTypeTo' + 'Float' + '()' eval(setDataType) importer.SetNumberOfScalarComponents(1) importer.SetWholeExtent(0,img.shape-1,0,img.shape-1,0,img.shape-1) importer.SetDataExtentToWholeExtent() importer.Update() volume = slicer.vtkMRMLScalarVolumeNode() volume.SetName("image") volume.SetAndObserveImageData(importer.GetOutput()) slicer.mrmlScene.AddNode(volume) volumeDisplayNode = 0 volumeDisplayNode = slicer.vtkMRMLScalarVolumeDisplayNode() slicer.mrmlScene.AddNode(volumeDisplayNode) greyColorTable = slicer.util.getNode('Grey') volumeDisplayNode.SetAndObserveColorNodeID(greyColorTable.GetID()) volume.SetAndObserveDisplayNodeID(volumeDisplayNode.GetID()) volume.SetSpacing(xrat,yrat,zrat) selectionNode = slicer.app.applicationLogic().GetSelectionNode() selectionNode.SetReferenceActiveVolumeID(volume.GetID()) slicer.app.applicationLogic().PropagateVolumeSelection(0)
Via trial and error I’ve isolated the two lines that cause the crash as:
Obviously (or maybe not, I’m not sure), without these two lines the image doesn’t show, but nor does it crash. I don’t personally know too much about slicer, but have experience programming in python. Is there another way I can represent the data so that it doesn’t take up too much space so slicer can read it? Alternatively, is there another function I can use to cause slicer to display the volume. Any advice would be appreciated! Thanks!