<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"><<a href="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</a>></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<short to float>, InternalFilter is from another CasterImageFilter<float to short int></div>
<div> </div>
<div>Basical, the image direction and resolution are all correct.</div>
<div> </div>
<div> </div>
<div> </div>
<div>template <unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale, class TDimension></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< InternalImageType > WriterType1;<br> typename WriterType1::Pointer writer1=WriterType1::New();<br> typedef itk::CastImageFilter< InputImageType,InternalImageType> CastingFilterType1;<br>
typename CastingFilterType1::Pointer caster11 = CastingFilterType1::New();</div>
<div> typedef itk::CastImageFilter< InternalImageType,OutputImageType> CastingFilterType2;<br> typename CastingFilterType1::Pointer caster21 = CastingFilterType1::New();</div>
<div> typedef itk::RecursiveGaussianImageFilter< <br> InternalImageType,<br> InternalImageType > GaussianFilterType;</div>
<div> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< <br> InternalImageType, <br> InternalImageType > GradientFilterType;</div>
<div> typename GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();<br> <br> const double sigma =(float)1.0;<br> // gradientMagnitude-SetSpacing( InputFilter->GetOutput()->GetSpacing() );<br>
<br> gradientMagnitude->SetSigma( sigma );<br> gradientMagnitude->SetInput(InputFilter->GetOutput());<br> <br> writer1->SetFileName("../data/gradient.hdr");<br> writer1->SetInput(gradientMagnitude->GetOutput());<br>
InternalFilter->SetInput(gradientMagnitude->GetOutput());<br> gradientMagnitude->Update();</div>
<div><br>//to set seed points<br> </div>
<div> typedef itk::Point< double, InternalImageType::ImageDimension > InternalPointType;<br> InternalPointType point;<br> point[0]=77; point[1]=190;point[2]=90;<br> typedef itk::Index< InternalImageType::ImageDimension > IndexType;<br>
IndexType index;<br> gradientMagnitude->GetOutput()->TransformPhysicalPointToIndex( point, index );<br> std::cout << "index" << index << std::endl;<br> std::cout << "gradient image spacing"<<gradientMagnitude->GetOutput()->GetSpacing() << std::endl;<br>
std::cout << "function input spacing"<<InputFilter->GetOutput()->GetSpacing() << std::endl;<br> std::cout << "gradient image direction"<<gradientMagnitude->GetOutput()->GetDirection() << std::endl;<br>
std::cout << "function input
direction"<<InputFilter->GetOutput()->GetDirection() << std::endl;</div>
<div> </div>
<div> </div>
<div> </div>
<div> <br>// <br>// // InternalFilter->SetInput(InputFilter->GetOutput());<br>// <br> try<br> {<br> writer1->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br>
std::cerr << "Exception caught !" << std::endl;<br> std::cerr << excep << std::endl;<br> }</div>
<div>std::cout << InternalFilter->GetOutput()->GetSpacing() << std::endl;<br> <br> <br> <br> <br> <br>};</div>
<div> </div>
<div>#endif</div></div><br>
</div></blockquote></div><br>