[Insight-users] resize image

Luis Ibanez luis.ibanez at kitware.com
Tue, 06 Jan 2004 18:47:31 -0500


Hi Corinne

What is the goal that you pursue by resizing the image ?


A) Do you want to have as a result the same image
    with an additional band of pixels around ?

    or

B) Do you simply want to get a larger size and
    don't care about discarding the original
    content of the image ?

If you are in case (A) you may want to use the PasteImageFilter
http://www.itk.org/Insight/Doxygen/html/classitk_1_1PasteImageFilter.html


If you are in case (B) the best way to go is simply
to create a new image. You could recover the origin
and spacing information from the original image...
but you have to think twice if the origin should be
conserved or should be shifted...


The code will look like:

   // get the original image
   ImageType::ConstPointer image1 = GetImageSomehow();

   // prepare new size
   ImageType::SizeType  size;
   ImageType::IndexType start;
   ImageType::RegionType  region;

   size[0] = 512;  // new image size
   size[1] = 512;
   size[2] = 512;

   start[0] = 0;  // or maybe start somewhere else... ?
   start[1] = 0;
   start[2] = 0;

   region.SetSize( size );
   region.SetIndex( start );

   ImageType::Pointer image2 = ImageType::New();

   // copy origin and spacing
   image2->CopyInformation( image1 );

   image2->SetRegions( region );
   image2->Allocate();



The error message that you are getting seem
to indicate that you are trying to call SetRegions()
in a ConstPointer. Const-ness will not allow you
to modify the regions of an image.  Note also that
you don't want to do this on the output of a filter
since the image is owned and controled by the filter.

Any subsequent call to Update() on the filter will
reset the content of the image and override your
modifications.



Please let us know if you have further questions,


  Thanks


    Luis



--------------------------
Corinne Mattmann wrote:

> Hi,
> 
> I would like to resize my image (index and size). What's the easiest way
> to do this?
> I tried something like this:
> 
> 	typedef ImageRegion<ImageDimension> ImageRegionType;
> 	ImageRegionType region;
> 	typedef Index<ImageDimension> IndexType;
> 	IndexType index;
> 	typedef Size<ImageDimension> SizeType;
> 	SizeType size;
> 	const long in[3] = {0,0,0};
> 	index.SetIndex(in);
> 	const unsigned long si[3] = {50,50,50};
> 	size.SetSize(si);
> 	region.SetIndex(index);
> 	region.SetSize(size);
> 	image->SetRegions(region);
> 
> But I got the following error:
> 
> 	error C2663: 'SetRegions' : 2 overloads have no legal conversion
> for 'this' pointer
> 
> 
> Thanks very much,
> Corinne Mattmann
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>