I’m trying to perform a very simple operation on an image using Python. I just want to read it as a NumPy array, change some values and then write it back as a new image. The problem is: when I write it back, I lose the original origin and orientation (that’s a mouthful). Is there any way I can keep them? The code is as simple as this:
I think the function you need it itk.GetArrayViewFromImage. That will modify ITK’s version of the image. Then just write that - all metadata will go along.
Thank you for your reply @dzenanz. Unfortunately, that didn’t work. I even tried replacing itk.GetImageFromArray with itk.GetImageViewFromArray, but that didn’t work either.