# Sitk composite image

**URL:** https://discourse.itk.org/t/sitk-composite-image/2514
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [December 12, 2019, 4:02am UTC](https://discourse.itk.org/t/sitk-composite-image/2514 "2019-12-12T04:02:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [December 12, 2019, 4:02am UTC](https://discourse.itk.org/t/sitk-composite-image/2514/1 "2019-12-12T04:02:34Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [December 12, 2019, 3:29pm UTC](https://discourse.itk.org/t/sitk-composite-image/2514/2 "2019-12-12T15:29:59Z")

</div>

Hello,

The following works for me:

```auto
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.

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [December 12, 2019, 5:38pm UTC](https://discourse.itk.org/t/sitk-composite-image/2514/3 "2019-12-12T17:38:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [December 12, 2019, 7:05pm UTC](https://discourse.itk.org/t/sitk-composite-image/2514/5 "2019-12-12T19:05:40Z")

</div>

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.

```auto
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.

```
