[Insight-users] index problem

Luis Ibanez luis.ibanez at kitware.com
Thu, 08 Jan 2004 16:32:23 -0500


Hi Corinne,

Lydia and I looked closely at the problem you
reported and it seems that it is simply due to
the necessary truncation of the starting index
done during the image reduction.

If you anticipate that you need to shrink and
expand the image and want to be able to keep
their region totally coincident you must select
an image region that has starting index and size
that are divisible by the shrink/expand factor.

For example, if you plan to use shrink/expand
factors

               [3,2,5]

you have to select

     index[0] = multiple of 3
     index[1] = multiple of 2
     index[2] = multiple of 5

and

     size[0] = multiple of 3
     size[1] = multiple of 2
     size[2] = multiple of 5

for example

     index = [6,4,5]
     size  = [900,800,555]

in this case the shrink with factors [3,2,5]
will give you an image with region

     shrinkedindex = [2,2,1]
     shrinkedsize  = [300,400,111]

and the further expand will produce

   expandshrinkedindex = [6,4,5]
   expandshrinkedsize  = [900,800,555]

which fully corresponds to the original
image region, and therefore you can use
a common region for controlling two
iterators, one visitin the input image
and the other visiting the ShrinkedExpanded
image.



Regards,


    Luis



--------------------
Lydia Ng wrote:

> Hi Corinne,
> 
> Would you mind posting some code that illustrates this problem?
> I.e. how the various filter is being used.
> I am curious if the problem lies with the indexing or the interaction between
> the filters or if some fundamental assumption were made in the algorithm that
> assume zero starting index.
> 
> Thanks,
> Lydia
> 
> 
> 
>>-----Original Message-----
>>From: Corinne Mattmann [mailto:mattmaco at ee.ethz.ch]
>>Sent: Tuesday, January 06, 2004 4:26 PM
>>To: 'Luis Ibanez'
>>Cc: insight-users at itk.org
>>Subject: RE: [Insight-users] index problem
>>
>>Hi Luis,
>>
>>Thanks for your answer. I would like to make my image smaller with the
>>same content (cut some pixels away at the border and set another index),
>>so I think A) should work.
>>At the moment I have another questions:
>>I am programming a filter which registers two images with the demons
>>algorithm using a multi-resolution pyramid. To set up the pyramid I'm
>>using itkRecursiveMultiResolutionPyramidImageFilter.
>>If I have an image with index [3,1,1] and if I reduce it by a factor of
>>2, the output of the pyramid would be an image with index [2,1,1].
>>This images I input into the demons-filter and get as output a
>>deformable field with the same index. So far so good.
>>But if I now expand this deformable field with the
>>itkVectorExpandImageFilter, I get an image with index [4,2,2], which
>>results in an error when I apply it to the images with index [3,1,1].
>>Took me quite long to find this problem ;-)
>>I wanted to set the "right" index at the expand filter but I couldn't
>>find an appropriate function. What solution do you suggest?
>>
>>Thanks very much for your answer and have a nice evening,
>>Corinne
>>
>>
>>-----Original Message-----
>>From: Luis Ibanez [mailto:luis.ibanez at kitware.com]
>>Sent: Tuesday, January 06, 2004 4:48 PM
>>To: Corinne Mattmann
>>Cc: insight-users at itk.org
>>Subject: Re: [Insight-users] resize image
>>
>>
>>
>>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.htm
>>l
>>
>>
>>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
>>>
>>
>>
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>