From 57a7a98b6e18eefe30eb1027cb50f699498a3037 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Mon, 4 Oct 2010 07:48:42 +0000 Subject: [PATCH] add "get number of connected components" function --- itk/clitkSegmentationUtils.h | 8 ++++++++ itk/clitkSegmentationUtils.txx | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) 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 -- 2.47.1