[Insight-users] copying an image into another

Luis Ibanez luis . ibanez at kitware . com
Fri, 30 Aug 2002 10:56:37 -0400


Hi Zein,

You can use Iterators for copying the data from
one image to another. Something like the following
code should do it:

// Let's assume:
//
// ImageTypeA::Pointer src
// ImageTypeB::Pointer dst

#include "itkImageRegionIterator"
ImageTypeA::RegionType region = src->GetBufferedRegion();
itk::ImageRegionIterator< ImageTypeA > srcit( src, region );
itk::ImageRegionIterator< ImageTypeA > dstit( dst, region );
srcit.GoToBegin();
dstit.GoToBegin();

while( !srcit.IsAtEnd() )
   {
   dstit.Set(
          static_cast< ImageTypeB::PixelType >(
                                     srcit.Get() )
             );
   ++srcit;
   ++dstit;
   }


If ImageTypeA and ImageTypeB are the same, you can get
rid of the static_cast<> in the while loop and just
do:

   dstit.Set(  srcit.Get() );


This code assumes that you have already allocated
both images and that they have the same size.

--------------

Just for the record,
Why do you want to copy one image into another ?

There may be exising ImageFilter for the process
that you are trying to apply...

or this may be a filter that we will be interested
to add to the toolkit.


Thanks


Luis


================================================

Zein Salah wrote:
> Hi Friends,
> 
>  
> 
> I have two itk::image objects. Both of them is already allocated.
> 
> I want to copy one of them into the other. How can I do that?????
> 
>  
> 
> Many thanks,,,,
> 
>  
> 
> Zein
> 
>  
> 
>  
> 
> ->8<------------->8<------------->8<------------->8<------------->8<------------->8<-
> Zein I. Salah
> Universität Tübingen, WSI-GRIS
> Sand 14
> 72076 Tübingen
> Email: salah@gris.uni-tuebingen.de <mailto:salah@gris.uni-tuebingen.de>  
> / zeinsalah@hotmail.com <mailto:zeinsalah@hotmail.com>
> Tel.: (07071) 29 75465 (GRIS) , (07071) 96 44 39 (privat)
>