<br>Hi Baoyn,<br><br>It is perfectly valid to get Indices with negative components when<br>using TransformPhysicalPointToIndex().<br><br>It is *your* responsibility to test for the indices to be inside of the<br>image before you use them to access data.<br>
<br>This can be done with <br><br>the IsInside() method of the ImageRegion class, and/or with <br>the IsInsideBuffer()  method of the Interpolators.<br><br><br>This being said,<br>It is not a bad idea to double check your computation, to<br>
make sure that there is not  a bug in the conversion.<br><br><br><br>    Regards,<br><br><br>          Luis<br><br><br>----------------------------------------------------------------------------------<br><div class="gmail_quote">
On Wed, Feb 25, 2009 at 4:20 PM, Baoyun Li <span dir="ltr">&lt;<a href="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div>Dear Luis and All:</div>
<div> </div>
<div>I am trying to put some seed point for confidence level set segmenation. I give physical points: </div>
<div>point[0]=77; point[1]=190;point[2]=90; </div>
<div>and using  TransformPhysicalPointToIndex( point, index ) to get index; my image resolution is  [1.3 1.3 1.3]</div>
<div> </div>
<div>the index I got is 58 -143 67. The y index is negative.</div>
<div> </div>
<div>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</div>
<div> </div>
<div>It is clear 0 -1 0 of y axis direction cosine gives me the negative index. Can somebody teach me to solve this problem?</div>
<div> </div>
<div> </div>
<div>Best regards and thanks  a lot.</div>
<div> </div>
<div>Baoyun<br><br></div>
<div>Below is my template function,  InputerFilter is derived from CasterImageFilter&lt;short to float&gt;, InternalFilter is from another CasterImageFilter&lt;float to short int&gt;</div>
<div> </div>
<div>Basical, the image direction and resolution are all correct.</div>
<div> </div>
<div> </div>
<div> </div>
<div>template &lt;unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale, class TDimension&gt;</div>
<div>void GradientConfidence( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale)<br>{<br>    typedef typename TInputFilter::InputImageType OutputImageType;<br>  typedef typename TInternalFilter::InputImageType InternalImageType;<br>
  typedef typename TInternalFilter::OutputImageType InputImageType;<br>   //typedef  TInputFilter InputImageType;</div>
<div>  typedef itk::ImageFileWriter&lt; InternalImageType &gt;  WriterType1;<br>  typename WriterType1::Pointer writer1=WriterType1::New();<br>  typedef  itk::CastImageFilter&lt; InputImageType,InternalImageType&gt; CastingFilterType1;<br>
  typename CastingFilterType1::Pointer caster11 = CastingFilterType1::New();</div>
<div>  typedef itk::CastImageFilter&lt; InternalImageType,OutputImageType&gt; CastingFilterType2;<br>  typename CastingFilterType1::Pointer caster21 = CastingFilterType1::New();</div>
<div>  typedef itk::RecursiveGaussianImageFilter&lt; <br>                                InternalImageType,<br>                                 InternalImageType &gt; GaussianFilterType;</div>
<div>   typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter&lt; <br>                               InternalImageType, <br>                               InternalImageType &gt;  GradientFilterType;</div>
<div>  typename GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();<br>  <br>   const double sigma =(float)1.0;<br>  // gradientMagnitude-SetSpacing( InputFilter-&gt;GetOutput()-&gt;GetSpacing() );<br>
  <br>   gradientMagnitude-&gt;SetSigma(  sigma  );<br>   gradientMagnitude-&gt;SetInput(InputFilter-&gt;GetOutput());<br>  <br>   writer1-&gt;SetFileName(&quot;../data/gradient.hdr&quot;);<br>   writer1-&gt;SetInput(gradientMagnitude-&gt;GetOutput());<br>
   InternalFilter-&gt;SetInput(gradientMagnitude-&gt;GetOutput());<br>   gradientMagnitude-&gt;Update();</div>
<div><br>//to set seed points<br> </div>
<div>   typedef itk::Point&lt; double, InternalImageType::ImageDimension &gt; InternalPointType;<br>   InternalPointType point;<br>   point[0]=77; point[1]=190;point[2]=90;<br>   typedef itk::Index&lt; InternalImageType::ImageDimension &gt; IndexType;<br>
   IndexType index;<br>   gradientMagnitude-&gt;GetOutput()-&gt;TransformPhysicalPointToIndex( point, index );<br>   std::cout &lt;&lt; &quot;index&quot; &lt;&lt; index &lt;&lt; std::endl;<br>   std::cout &lt;&lt; &quot;gradient image spacing&quot;&lt;&lt;gradientMagnitude-&gt;GetOutput()-&gt;GetSpacing() &lt;&lt; std::endl;<br>
   std::cout &lt;&lt; &quot;function input spacing&quot;&lt;&lt;InputFilter-&gt;GetOutput()-&gt;GetSpacing() &lt;&lt; std::endl;<br>   std::cout &lt;&lt; &quot;gradient image direction&quot;&lt;&lt;gradientMagnitude-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;<br>
   std::cout &lt;&lt; &quot;function input
 direction&quot;&lt;&lt;InputFilter-&gt;GetOutput()-&gt;GetDirection() &lt;&lt; std::endl;</div>
<div> </div>
<div> </div>
<div> </div>
<div>     <br>// <br>//  // InternalFilter-&gt;SetInput(InputFilter-&gt;GetOutput());<br>//    <br>    try<br>       {<br>      writer1-&gt;Update();<br>       }<br>     catch( itk::ExceptionObject &amp; excep )<br>      {<br>
       std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>       std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>       }</div>
<div>std::cout &lt;&lt; InternalFilter-&gt;GetOutput()-&gt;GetSpacing() &lt;&lt; std::endl;<br> <br>   <br>   <br>  <br>  <br>};</div>
<div> </div>
<div>#endif</div></div><br>



      </div></blockquote></div><br>