[Insight-users] confused behavior of itk image origin with FlipImageFilter

Peter Cech pcech at vision.ee.ethz.ch
Sun Dec 24 09:29:49 EST 2006


On Sun, Dec 24, 2006 at 03:34:01 -0500, kdsfinger at gmail.com wrote:
> hi, there
> To make things simple, let's define two 4x2 (2D) images: img0 and
> img1. Both with spacing 1mm on x and y direction.
> img0 has pixel value
> 1 2 3 4
> 5 6 7 8
> img0 has origin (0,0).
> img1 is produced by a FlipImageFilter with img0 as input and flip on x
> axis, thus img1 has pixel value
> 4 3 2 1 // We call this configuration
> 8 7 6 5 // confA.
> After flipping of img0, img1 has origin (-3, 0). (Why?)

This is the correct default behavior. It flips (mirrors) the image about
a hyperplane defined by equation "flip_axis == 0". Here it is x==0,
which corresponds to flipping/mirroring about axis y.

You can get an alternative behaviour, that flips the image without
moving it, by calling FlipAboutOriginOff().
http://www.itk.org/Doxygen/html/classitk_1_1FlipImageFilter.html#itk_1_1FlipImageFilterz609_0

> Experiment 1:
> I output img1 and it shows as confA.
> Later, I set the origin of img1 to (0,0) and output img1, it still
> shows as confA.
> 
> Experiment 2:
> I resample img1 with identity transformation and output the result, it
> shows as confA.
> Later, I set the origin of img1 to (0,0) and resample img1 with
> identity transformation and output the result, it still shows as
> confA.
> 
> Here is the code for resampling:
> --------------------------
>  resampler->SetTransform( identityTransform );
>  resampler->SetInput( img1 );
>  resampler->SetSize(   img1->GetLargestPossibleRegion().GetSize() );
>  resampler->SetOutputOrigin( img1->GetOrigin() );
>  resampler->SetOutputSpacing( img1->GetSpacing() );
>  resampler->SetDefaultPixelValue( 100 );
> ---------------------------
> 
> My question is: If I change the origin of an image and resample it
> based on the new origin, the result must be different from the
> original one (image shifted). Why in this case, with the origin
> changed, there is no difference for the output? What is the exact
> defination of origin and how to use it correctly? I do read the
> softwareguide but still can't explain why.


Origin is always coordinate of a pixel with index [0,0] in physical
space. This means, that changing origin is equivalent to translating the
image in physical space. Your above experiment your input image was
already shifted, so the output will be identical to input.

I hope this will help you.

Peter


More information about the Insight-users mailing list