Describe the bug
Metadata is incorrectly read from the MHA file: some characters are removed.
To Reproduce
Steps to reproduce the behavior:
- Operating system, version, and architecture
- OS: Fedora
- Architecture: x86
- Programming language: Python 3.12
- Version of SimpleITK: 2.3.1
- How was SimpleITK installed? pip
- A minimal working example which causes the error.
rom pathlib import Path
import SimpleITK as sitk
import numpy as np
path = Path("/tmp/test.mha")
img = sitk.GetImageFromArray(np.zeros((2,2,2)))
img.SetMetaData("test1", "des caractères spéciaux")
img.SetMetaData("test2", "des caractères spéciö")
sitk.WriteImage(img, str(path))
img2 = sitk.ReadImage(str(path))
print(img2.GetMetaData("test1")) # output: "des caractères spéciaux"
print(img2.GetMetaData("test2")) # output: "des caractères spéci"
for line in path.open("r"):
if line.startswith("test"):
print(line)
# output:
# test1 = des caractères spéciaux
# test2 = des caractères spéciö
# which shows that the content of the MHA is correctly written, but not correctly read
Expected behavior
img2.GetMetaData("test2") should return "des caractères spéciö" instead of "des caractères spéci"
I suspect some unicode black magic is at work here.
Describe the bug
Metadata is incorrectly read from the MHA file: some characters are removed.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
img2.GetMetaData("test2")should return"des caractères spéciö"instead of"des caractères spéci"I suspect some unicode black magic is at work here.