[Insight-users] get negative index by----TransformPhysicalPointToIndex

Luis Ibanez luis.ibanez at kitware.com
Wed Feb 25 17:00:21 EST 2009


Hi Baoyn,

It is perfectly valid to get Indices with negative components when
using TransformPhysicalPointToIndex().

It is *your* responsibility to test for the indices to be inside of the
image before you use them to access data.

This can be done with

the IsInside() method of the ImageRegion class, and/or with
the IsInsideBuffer()  method of the Interpolators.


This being said,
It is not a bad idea to double check your computation, to
make sure that there is not  a bug in the conversion.



    Regards,


          Luis


----------------------------------------------------------------------------------
On Wed, Feb 25, 2009 at 4:20 PM, Baoyun Li <baoyun_li123 at yahoo.com> wrote:

> Dear Luis and All:
>
> I am trying to put some seed point for confidence level set segmenation. I
> give physical points:
> point[0]=77; point[1]=190;point[2]=90;
> and using  TransformPhysicalPointToIndex( point, index ) to get index; my
> image resolution is  [1.3 1.3 1.3]
>
> the index I got is 58 -143 67. The y index is negative.
>
> I checked the image direction in my template function, it is 1 0 0; 0 -1 0;
> 0 0 1. The direction is consistent with the image I read in the main
> program, and the resolution of the image is also correct
>
> It is clear 0 -1 0 of y axis direction cosine gives me the negative index.
> Can somebody teach me to solve this problem?
>
>
> Best regards and thanks  a lot.
>
> Baoyun
>
> Below is my template function,  InputerFilter is derived from
> CasterImageFilter<short to float>, InternalFilter is from another
> CasterImageFilter<float to short int>
>
> Basical, the image direction and resolution are all correct.
>
>
>
> template <unsigned int Dim,class TInputFilter, class TInternalFilter, class
> TScale, class TDimension>
> void GradientConfidence( TInputFilter* InputFilter, TInternalFilter*
> InternalFilter, TScale scale)
> {
>     typedef typename TInputFilter::InputImageType OutputImageType;
>   typedef typename TInternalFilter::InputImageType InternalImageType;
>   typedef typename TInternalFilter::OutputImageType InputImageType;
>    //typedef  TInputFilter InputImageType;
>   typedef itk::ImageFileWriter< InternalImageType >  WriterType1;
>   typename WriterType1::Pointer writer1=WriterType1::New();
>   typedef  itk::CastImageFilter< InputImageType,InternalImageType>
> CastingFilterType1;
>   typename CastingFilterType1::Pointer caster11 =
> CastingFilterType1::New();
>   typedef itk::CastImageFilter< InternalImageType,OutputImageType>
> CastingFilterType2;
>   typename CastingFilterType1::Pointer caster21 =
> CastingFilterType1::New();
>   typedef itk::RecursiveGaussianImageFilter<
>                                 InternalImageType,
>                                  InternalImageType > GaussianFilterType;
>    typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
>                                InternalImageType,
>                                InternalImageType >  GradientFilterType;
>   typename GradientFilterType::Pointer  gradientMagnitude =
> GradientFilterType::New();
>
>    const double sigma =(float)1.0;
>   // gradientMagnitude-SetSpacing( InputFilter->GetOutput()->GetSpacing()
> );
>
>    gradientMagnitude->SetSigma(  sigma  );
>    gradientMagnitude->SetInput(InputFilter->GetOutput());
>
>    writer1->SetFileName("../data/gradient.hdr");
>    writer1->SetInput(gradientMagnitude->GetOutput());
>    InternalFilter->SetInput(gradientMagnitude->GetOutput());
>    gradientMagnitude->Update();
>
> //to set seed points
>
>    typedef itk::Point< double, InternalImageType::ImageDimension >
> InternalPointType;
>    InternalPointType point;
>    point[0]=77; point[1]=190;point[2]=90;
>    typedef itk::Index< InternalImageType::ImageDimension > IndexType;
>    IndexType index;
>    gradientMagnitude->GetOutput()->TransformPhysicalPointToIndex( point,
> index );
>    std::cout << "index" << index << std::endl;
>    std::cout << "gradient image
> spacing"<<gradientMagnitude->GetOutput()->GetSpacing() << std::endl;
>    std::cout << "function input
> spacing"<<InputFilter->GetOutput()->GetSpacing() << std::endl;
>    std::cout << "gradient image
> direction"<<gradientMagnitude->GetOutput()->GetDirection() << std::endl;
>    std::cout << "function input
> direction"<<InputFilter->GetOutput()->GetDirection() << std::endl;
>
>
>
>
> //
> //  // InternalFilter->SetInput(InputFilter->GetOutput());
> //
>     try
>        {
>       writer1->Update();
>        }
>      catch( itk::ExceptionObject & excep )
>       {
>        std::cerr << "Exception caught !" << std::endl;
>        std::cerr << excep << std::endl;
>        }
> std::cout << InternalFilter->GetOutput()->GetSpacing() << std::endl;
>
>
>
>
>
> };
>
> #endif
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090225/a68224e3/attachment.htm>


More information about the Insight-users mailing list