Sitk composite image

How can one write a composite image to png with sitk?

Currently I cast a composite image with three components to vectorUint8, but when I try to write it to file it gives and itk error. Any suggestions or alternatives?

Hello,

The following works for me:

sitk.WriteImage(sitk.Image([10,10], sitk.sitkVectorUInt8, 3), "foo.png")           

Please describe in detail what you are going, provide minimal reproducible code, and include the error message received. The work needed to reduce your problem to a minimal example frequently revels a bug in the code, and produced a shareable example for other to help with otherwise.

1 Like

Thank you @blowekamp. I need to pull out the essential part from the tangle and will post some code. I think maybe the issue could be related to , 3) but I will investigate and reply with a minimal example.

I compared the image you showed and the image I am trying to save and look identical except for the size of the image.

The issue was that the folder I want to write to wasn’t there, but the error was cryptic which makes sense now.

Traceback (most recent call last):
  File "create_stack.py", line 112, in <module>
    main()
  File "create_stack.py", line 108, in main
    writer.Execute(new_image)
  File "/Users/sansomk/anaconda3/envs/reg/lib/python3.7/site-packages/SimpleITK-1.2.0rc2.dev1162+g2a79d-py3.7-macosx-10.7-x86_64.egg/SimpleITK/SimpleITK.py", line 6808, in Execute
    return _SimpleITK.ImageFileWriter_Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK ImageFileWriter_Execute: /Users/sansomk/build/simpleelastix/build/ITK/Modules/IO/PNG/src/itkPNGImageIO.cxx:543:
Problem while opening the file.
2 Likes