]> Creatis software - clitk.git/commitdiff
add "get number of connected components" function
authordsarrut <dsarrut>
Mon, 4 Oct 2010 07:48:42 +0000 (07:48 +0000)
committerdsarrut <dsarrut>
Mon, 4 Oct 2010 07:48:42 +0000 (07:48 +0000)
itk/clitkSegmentationUtils.h
itk/clitkSegmentationUtils.txx

index 09b0844a7271f36cb071da0cf6f542ea097eec06..80d4e93eab56cbd3ce7da2ccf8c929f1c519ad48 100644 (file)
@@ -70,6 +70,14 @@ namespace clitk {
   //--------------------------------------------------------------------
 
 
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  int GetNumberOfConnectedComponentLabels(typename ImageType::Pointer input, 
+                                          typename ImageType::PixelType BG, 
+                                          bool isFullyConnected);
+  //--------------------------------------------------------------------
+
+
   //-------------------------------------------------------------------- 
   template<class TImageType>
   typename TImageType::Pointer
index 0f5ebfbd58b9f7a9888e906091129b48909737e2..e031079bfcb505f6c5a210869d27917a06a85801 100644 (file)
@@ -127,6 +127,24 @@ clitk::SetBackground(typename ImageType::ConstPointer input,
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+template<class ImageType>
+int clitk::GetNumberOfConnectedComponentLabels(typename ImageType::Pointer input, 
+                                               typename ImageType::PixelType BG, 
+                                               bool isFullyConnected) {
+  // Connected Component label 
+  typedef itk::ConnectedComponentImageFilter<ImageType, ImageType> ConnectFilterType;
+  typename ConnectFilterType::Pointer connectFilter = ConnectFilterType::New();
+  connectFilter->SetInput(input);
+  connectFilter->SetBackgroundValue(BG);
+  connectFilter->SetFullyConnected(isFullyConnected);
+  connectFilter->Update();
+  
+  // Return result
+  return connectFilter->GetObjectCount();
+}
+//--------------------------------------------------------------------
+
 //--------------------------------------------------------------------
 template<class ImageType>
 typename ImageType::Pointer