From: dsarrut Date: Mon, 4 Oct 2010 07:48:42 +0000 (+0000) Subject: add "get number of connected components" function X-Git-Tag: v1.2.0~374 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=57a7a98b6e18eefe30eb1027cb50f699498a3037;p=clitk.git add "get number of connected components" function --- diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index 09b0844..80d4e93 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -70,6 +70,14 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + int GetNumberOfConnectedComponentLabels(typename ImageType::Pointer input, + typename ImageType::PixelType BG, + bool isFullyConnected); + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template typename TImageType::Pointer diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index 0f5ebfb..e031079 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -127,6 +127,24 @@ clitk::SetBackground(typename ImageType::ConstPointer input, //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +int clitk::GetNumberOfConnectedComponentLabels(typename ImageType::Pointer input, + typename ImageType::PixelType BG, + bool isFullyConnected) { + // Connected Component label + typedef itk::ConnectedComponentImageFilter ConnectFilterType; + typename ConnectFilterType::Pointer connectFilter = ConnectFilterType::New(); + connectFilter->SetInput(input); + connectFilter->SetBackgroundValue(BG); + connectFilter->SetFullyConnected(isFullyConnected); + connectFilter->Update(); + + // Return result + return connectFilter->GetObjectCount(); +} +//-------------------------------------------------------------------- + //-------------------------------------------------------------------- template typename ImageType::Pointer