<html><div style='background-color:'><DIV class=RTE>Hello all,</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Does anyone have experience with how to itkSampleMeanShiftClusteringFilter.txx in itk? Also, would it work for 3d images? Thanks alot,</DIV>
<DIV class=RTE>Eric</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE><FONT size=2>/*=========================================================================</DIV>
<DIV class=RTE>
<P>Program: Insight Segmentation & Registration Toolkit</P>
<P>Module: $RCSfile: itkSampleMeanShiftClusteringFilter.txx,v $</P>
<P>Language: C++</P>
<P>Date: $Date: 2005/07/26 15:55:05 $</P>
<P>Version: $Revision: 1.5 $</P>
<P>Copyright (c) Insight Software Consortium. All rights reserved.</P>
<P>See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.</P>
<P>This software is distributed WITHOUT ANY WARRANTY; without even </P>
<P>the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR </P>
<P>PURPOSE. See the above copyright notices for more information.</P>
<P>=========================================================================*/</P>
<P>#ifndef __itkSampleMeanShiftClusteringFilter_txx</P>
<P>#define __itkSampleMeanShiftClusteringFilter_txx</P>
<P>#include "vnl/vnl_math.h"</P>
<P>namespace itk{ </P>
<P>namespace Statistics{</P>
<P>template< class TSample ></P>
<P>SampleMeanShiftClusteringFilter< TSample ></P>
<P>::SampleMeanShiftClusteringFilter()</P>
<P>{</P>
<P>m_Threshold = 0.5 ;</P>
<P>m_MinimumClusterSize = 16 ;</P>
<P>}</P>
<P>template< class TSample ></P>
<P>SampleMeanShiftClusteringFilter< TSample ></P>
<P>::~SampleMeanShiftClusteringFilter()</P>
<P>{</P>
<P>}</P>
<P>template< class TSample ></P>
<P>void</P>
<P>SampleMeanShiftClusteringFilter< TSample ></P>
<P>::PrintSelf(std::ostream& os, Indent indent) const</P>
<P>{</P>
<P>Superclass::PrintSelf(os,indent);</P>
<P>os << indent << "Threshold: " << m_Threshold << std::endl ;</P>
<P>os << indent << "Minimum cluster size: " << m_MinimumClusterSize</P>
<P><< std::endl ;</P>
<P>}</P>
<P>template< class TSample ></P>
<P>void</P>
<P>SampleMeanShiftClusteringFilter< TSample ></P>
<P>::GenerateData()</P>
<P>{</P>
<P>const TSample* inputSample = this->GetInputSample() ;</P>
<P>m_Output.clear() ;</P>
<P>m_Output.resize( inputSample->Size(), 0 ) ;</P>
<P>int currentLabel = 1 ;</P>
<P>unsigned long currentClusterSize ;</P>
<P>SearchResultVectorType queryPoints ;</P>
<P>SearchResultVectorType queryPoints2 ;</P>
<P>MeasurementVectorType tempQueryPoint;</P>
<P>MeasurementVectorType tempPreviousQueryPoint;</P>
<P>bool searchLoopBegin ;</P>
<P>SearchResultVectorType tempSearchResult ;</P>
<P>SearchResultVectorType* currentQueryPoints ;</P>
<P>SearchResultVectorType* nextQueryPoints ;</P>
<P>SearchResultVectorType* tempQueryPoints ;</P>
<P>typename SearchResultVectorType::iterator cp_iter ;</P>
<P>typename SearchResultVectorType::iterator cp_end ; </P>
<P>typename SearchResultVectorType::iterator sr_iter ;</P>
<P>typename SearchResultVectorType::iterator sr_end ;</P>
<P>typename TSample::ConstIterator iter = inputSample->Begin() ;</P>
<P>typename TSample::ConstIterator end = inputSample->End() ;</P>
<P>while ( iter != end )</P>
<P>{</P>
<P>if ( m_Output[iter.GetInstanceIdentifier()] == 0 )</P>
<P>{</P>
<P>currentClusterSize = 0 ;</P>
<P>currentQueryPoints = &queryPoints ;</P>
<P>nextQueryPoints = &queryPoints2 ;</P>
<P>currentQueryPoints->clear() ;</P>
<P>nextQueryPoints->clear() ;</P>
<P>currentQueryPoints->push_back( iter.GetInstanceIdentifier() ) ;</P>
<P>searchLoopBegin = true ;</P>
<P>tempPreviousQueryPoint.Fill(0) ;</P>
<P>while ( currentQueryPoints->size() > 0 )</P>
<P>{</P>
<P>cp_iter = currentQueryPoints->begin() ;</P>
<P>cp_end = currentQueryPoints->end() ;</P>
<P>while ( cp_iter != cp_end )</P>
<P>{</P>
<P>tempQueryPoint = inputSample->GetMeasurementVector( ( *cp_iter) ) ;</P>
<P>if ( !searchLoopBegin && tempQueryPoint == tempPreviousQueryPoint )</P>
<P>{</P>
<P>break ;</P>
<P>}</P>
<P>tempSearchResult.clear() ;</P>
<P>inputSample->Search( tempQueryPoint, m_Threshold,</P>
<P>tempSearchResult ) ;</P>
<P>tempPreviousQueryPoint = tempQueryPoint ;</P>
<P>if ( searchLoopBegin )</P>
<P>{</P>
<P>searchLoopBegin = false ;</P>
<P>}</P>
<P>sr_iter = tempSearchResult.begin() ;</P>
<P>sr_end = tempSearchResult.end() ;</P>
<P>while ( sr_iter != sr_end )</P>
<P>{</P>
<P>if ( m_Output[*sr_iter] == 0 ) </P>
<P>{</P>
<P>m_Output[*sr_iter] = currentLabel ;</P>
<P>nextQueryPoints->push_back( *sr_iter ) ;</P>
<P>++currentClusterSize ;</P>
<P>}</P>
<P>++sr_iter ;</P>
<P>} // end of while sr_iter</P>
<P>++cp_iter ;</P>
<P>} // end of cp_iter</P>
<P>tempQueryPoints = currentQueryPoints ;</P>
<P>currentQueryPoints = nextQueryPoints ;</P>
<P>nextQueryPoints = tempQueryPoints ;</P>
<P>nextQueryPoints->clear() ;</P>
<P>} // end of while (cp->size())</P>
<P>if ( currentClusterSize < m_MinimumClusterSize )</P>
<P>{</P>
<P>}</P>
<P>else</P>
<P>{</P>
<P>itkDebugMacro(<< "cluster label = " << currentLabel</P>
<P><< " cluster size = " << currentClusterSize) ;</P>
<P>++currentLabel ;</P>
<P>}</P>
<P>} // end of if</P>
<P>++iter ;</P>
<P>}</P>
<P>}</P>
<P> </P>
<P>} // end of namespace Statistics </P>
<P>} // end of namespace itk</P>
<P>#endif</P></FONT></DIV></div></html>