# Why is the image transformed into an all-black image?And the origin of the image doesn't change

**URL:** <https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731>\
**Category:** Uncategorized\
**Created:** [February 21, 2023, 8:16am UTC](https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731 "2023-02-21T08:16:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljjiayou](https://discourse.itk.org/user_avatar/discourse.itk.org/ljjiayou/32/3211_2.png) [@ljjiayou](https://discourse.itk.org/u/ljjiayou)\
**Post date:** [February 21, 2023, 8:16am UTC](https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731/1 "2023-02-21T08:16:26Z")

</div>

```python
def get_center(img):
    """
    This function returns the physical center point of a 3d sitk image
    :param img: The sitk image we are trying to find the center of
    :return: The physical center point of the image
    """
    width, height, depth = img.GetSize()
    return img.TransformIndexToPhysicalPoint((int(np.ceil(width/2)),
                                              int(np.ceil(height/2)),
                                              int(np.ceil(depth/2))))
center=get_center(moving_image)
transform = sitk.Euler3DTransform(center,1,1,1,(0,0,0))
img_trans=sitk.Resample(moving_image,moving_image, transform,sitk.sitkLinear, 0)
print(sitk.GetArrayFromImage(img_trans).max)
print(img_trans.GetOrigin())

```

---

<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:** [February 21, 2023, 1:37pm UTC](https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731/2 "2023-02-21T13:37:08Z")

</div>

Hello @ljjiayou,

Code is a bit confusing, let’s simplify.

First, get the physical center of an image:

```auto
center = image.TransformContinuousIndexToPhysicalPoint([sz/2 for sz in image.GetSize()])

```

Now let’s look at the transform:

```auto
transform = sitk.Euler3DTransform(center,1,1,1,(0,0,0))

```

The meaning of the above transform is rotate around the `center` point using the ZXY Euler order with a rotation of 1 radian (~57 degrees) around each axis, no translation.

Finally, a simpler resampling statement which is equivalent to the original code, and visualizing results, can be done as:

```auto
image_resampled = sitk.Resample(image, transform)
sitk.Show(image_resampled)

```

The meaning of the above resampling is, use the original image grid and resample the original image onto it by applying a rotation to each of the grid points.

You can gain a better understanding of what is happening if you work in 2D and use a 90degree rotation. Highly recommend going over the [resampling notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/21_Transforms_and_Resampling.ipynb).

---

<div class="post-metadata">

**Author:** ![ljjiayou](https://discourse.itk.org/user_avatar/discourse.itk.org/ljjiayou/32/3211_2.png) [@ljjiayou](https://discourse.itk.org/u/ljjiayou)\
**Post date:** [February 23, 2023, 8:49am UTC](https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731/3 "2023-02-23T08:49:47Z")

</div>

Thank you very much.

---

<div class="post-metadata">

**Author:** ![ljjiayou](https://discourse.itk.org/user_avatar/discourse.itk.org/ljjiayou/32/3211_2.png) [@ljjiayou](https://discourse.itk.org/u/ljjiayou)\
**Post date:** [February 23, 2023, 9:02am UTC](https://discourse.itk.org/t/why-is-the-image-transformed-into-an-all-black-image-and-the-origin-of-the-image-doesnt-change/5731/4 "2023-02-23T09:02:50Z")

</div>

Thank you very much. I still have a problem. After the rotation of the image, some parts will be missing. How can we enlarge the visual field of the image to get the complete image? My images are private and can’t be released. My images are 3D.
