# Copy Image into another image taking into account origin & spacing

**URL:** <https://discourse.itk.org/t/copy-image-into-another-image-taking-into-account-origin-spacing/3899>\
**Category:** Algorithms\
**Created:** [February 24, 2021, 6:18pm UTC](https://discourse.itk.org/t/copy-image-into-another-image-taking-into-account-origin-spacing/3899 "2021-02-24T18:18:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imikejackson](https://discourse.itk.org/user_avatar/discourse.itk.org/imikejackson/32/35_2.png) [@imikejackson](https://discourse.itk.org/u/imikejackson)\
**Post date:** [February 24, 2021, 6:18pm UTC](https://discourse.itk.org/t/copy-image-into-another-image-taking-into-account-origin-spacing/3899/1 "2021-02-24T18:18:37Z")

</div>

What would be the basic steps to copy a source image into an existing destination image that takes into account the origin and spacing of both?

I have googled a bit and found [https://itk.org/ITKExamples/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Documentation.html](https://itk.org/ITKExamples/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Documentation.html) but I’m unsure if need to figure out the starting XY pixel location or if I can just use a different set of parameters. Assume the destination image has a larger number of pixels and would completely encompass the source image.

Do I need to first resample the source image to have the same spacing as the destination image?

Thanks  
Mike Jackson

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [February 24, 2021, 7:00pm UTC](https://discourse.itk.org/t/copy-image-into-another-image-taking-into-account-origin-spacing/3899/2 "2021-02-24T19:00:25Z")

</div>

Yes, the images have to have the same spacing and orientation. Once you’ve resampled your source to do so, you can use the PasteImageFilter or Paste function to copy the pixels into the destination image.

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 8, 2021, 6:42pm UTC](https://discourse.itk.org/t/copy-image-into-another-image-taking-into-account-origin-spacing/3899/3 "2021-03-08T18:42:42Z")

</div>

Hi @imikejackson ,

To copy just the image information, i.e. spacing, origin, direction, there is [`itk::Image::CopyInformation()`](https://itk.org/Doxygen/html/classitk_1_1ImageBase.html#ab44e7bc88fc437c9a613a6beb50f37e3). To create a deep copy of an image, including the pixel buffer, there is [`itk::ImageDuplicator`](https://itk.org/Doxygen/html/classitk_1_1ImageDuplicator.html).
