# SimpleITK ImageFileWriter give a wrong tag

**URL:** <https://discourse.itk.org/t/simpleitk-imagefilewriter-give-a-wrong-tag/4334>\
**Category:** Beginner Questions\
**Created:** [August 15, 2021, 10:13am UTC](https://discourse.itk.org/t/simpleitk-imagefilewriter-give-a-wrong-tag/4334 "2021-08-15T10:13:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhang-qiang-github](https://discourse.itk.org/user_avatar/discourse.itk.org/zhang-qiang-github/32/1183_2.png) [@zhang-qiang-github](https://discourse.itk.org/u/zhang-qiang-github)\
**Post date:** [August 15, 2021, 10:13am UTC](https://discourse.itk.org/t/simpleitk-imagefilewriter-give-a-wrong-tag/4334/1 "2021-08-15T10:13:34Z")

</div>

I have some process for a image, and I want to save the result.

The complete code to save image is:

```auto
                writer = sitk.ImageFileWriter()
                writer.KeepOriginalImageUIDOn()
                writer.SetFileName(name)
                print(img.GetMetaData('0028|0030'))
                writer.Execute(img)
                tImg = sitk.ReadImage(name)
                print(tImg.GetMetaData('0028|0030'))

```

The tag of `0028|0030` is pixel spacing.

In the above code, I want to save `img`, and the printed information is:

```auto
0.34090909361839\0.34090909361839 
1\1 

```

The spacing of `img` is 0.34\0.34. But, when I write it and read it, the spacing is changed to be 1\1.

My enviornment is:

```auto
win 10
python 3.7
SimpleITK 2.0.2

```

Is there anything wrong with `sitk.ImageFileWrite()`?

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [August 15, 2021, 3:21pm UTC](https://discourse.itk.org/t/simpleitk-imagefilewriter-give-a-wrong-tag/4334/2 "2021-08-15T15:21:21Z")

</div>

Hello @zhang-qiang-github,

Please check the real pixel spacing for the image:

```auto
print(img.GetSpacing())

```

Likely this became `1,1` due to some processing done earlier in the code. This overrides the information found in the metadata dictionary when writing.

---

<div class="post-metadata">

**Author:** ![zhang-qiang-github](https://discourse.itk.org/user_avatar/discourse.itk.org/zhang-qiang-github/32/1183_2.png) [@zhang-qiang-github](https://discourse.itk.org/u/zhang-qiang-github)\
**Post date:** [August 16, 2021, 2:48am UTC](https://discourse.itk.org/t/simpleitk-imagefilewriter-give-a-wrong-tag/4334/3 "2021-08-16T02:48:37Z")

</div>

Thank you for your suggestion~~~

I use img.SetSpacing before writer.Execute, and it works. The result is correct.
