Script cli module output volume fails

i called i scriptd cli module and outputvolume is vtkMRMLVectorVolumeNode

Here is code in ctacli.py file and fusion_image is np array

ImageType = itk.Image[itk.F, 3]
itk_image = itk.PyBuffer[ImageType].GetImageFromArray(fusion_image)
writer = itk.ImageFileWriter[ImageType].New()
writer.SetFileName(sys.argv[6])
writer.SetInput(itk_image)
writer.UseCompressionOn()
writer.Update();

In main thread:

    fusion_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLVectorVolumeNode", "bone_blended")
    params['outputVolume']=fusion_node.GetID() 
    # ID is  C:/Users/xxx/AppData/Local/Temp/Slicer/CEGJC_vtkMRMLVectorVolumeNodeB.nrrd when running
    cliNode=slicer.cli.run(slicer.modules.ctacli,None, parameters=params,wait_for_completion=True)
    fusion_image= slicer.util.arrayFromVolume(fusion_node)

It runs without error when calling ctacli.py, but the file doesn’t exists.

output error is as below:

ctacli completed without errors

vtkMRMLStorageNode::ReadData: Failed to read node

vtkMRMLStorageNode::ReadData: Failed to read node (vtkMRMLVectorVolumeNode1) from filename=‘C:/Users/xxx/AppData/Local/Temp/Slicer/CEGJC_vtkMRMLVectorVolumeNodeB.nrrd’

To help you get help, it could be good to follow the guidelines here: https://sscce.org/

I mean that with the above code , script cli module cant generate output nrrd file and i dont know how to fix it

Thanks for you reply

What I meant by suggesting you look at the SSCCE guidance is that it’s difficult for others on this forum to help when you post fragments of code rather than a complete example. I can look at what you posted and maybe guess what’s going on but it’s also possible that your issue lies with some other code. The process of making the smallest possible example that replicates the issue you are asking about often leads you to solve the problem yourself, so it helps everyone.

@pieper
very grateful for your help and i will try later.

About this question, it is very urgent for me to do a simple example. i am sorry for that.

for output vtkMRMLVecotrVolumeNode in this script. i try to convert from numpy array [1000,1000,3] , then it fails. At last , i expanded the numpy dimension and it works. itk or simple itk api both fulfill the requirement

just add ‘fusion_image = np.expand_dims(fusion_image, axis=0)’ before outpu t *.nrrd file

1 Like