From 2c5b29073dc62b39d162f1b954bb3cbb238f7b33 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Tue, 22 Feb 2011 07:12:02 +0000 Subject: [PATCH] Add LabelizeAndCountNumberOfObjects --- itk/clitkSegmentationUtils.h | 7 +++++ itk/clitkSegmentationUtils.txx | 55 ++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index 7308b7a..aafe722 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -74,6 +74,13 @@ namespace clitk { typename TImageType::PixelType BG, bool isFullyConnected, int minimalComponentSize); + template + typename TImageType::Pointer + LabelizeAndCountNumberOfObjects(const TImageType * input, + typename TImageType::PixelType BG, + bool isFullyConnected, + int minimalComponentSize, + int & nb); //-------------------------------------------------------------------- diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index dccfc35..c8f976e 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -192,6 +192,53 @@ clitk::Labelize(const ImageType * input, relabelFilter->SetMinimumObjectSize(minimalComponentSize); relabelFilter->Update(); + // DD(relabelFilter->GetNumberOfObjects()); + // DD(relabelFilter->GetOriginalNumberOfObjects()); + // DD(relabelFilter->GetSizeOfObjectsInPhysicalUnits()[0]); + + // Return result + typename ImageType::Pointer output = relabelFilter->GetOutput(); + return output; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +/* + Warning : in this cas, we consider outputType like inputType, not + InternalImageType. Be sure it fits. + */ +template +typename ImageType::Pointer +clitk::LabelizeAndCountNumberOfObjects(const ImageType * input, + typename ImageType::PixelType BG, + bool isFullyConnected, + int minimalComponentSize, + int & nb) { + // InternalImageType for storing large number of component + typedef itk::Image InternalImageType; + + // Connected Component label + typedef itk::ConnectedComponentImageFilter ConnectFilterType; + typename ConnectFilterType::Pointer connectFilter = ConnectFilterType::New(); + // connectFilter->ReleaseDataFlagOn(); + connectFilter->SetInput(input); + connectFilter->SetBackgroundValue(BG); + connectFilter->SetFullyConnected(isFullyConnected); + + // Sort by size and remove too small area. + typedef itk::RelabelComponentImageFilter RelabelFilterType; + typename RelabelFilterType::Pointer relabelFilter = RelabelFilterType::New(); + // relabelFilter->ReleaseDataFlagOn(); // if yes, fail when ExplosionControlledThresholdConnectedImageFilter ??? + relabelFilter->SetInput(connectFilter->GetOutput()); + relabelFilter->SetMinimumObjectSize(minimalComponentSize); + relabelFilter->Update(); + + nb = relabelFilter->GetNumberOfObjects(); + // DD(relabelFilter->GetNumberOfObjects()); + // DD(relabelFilter->GetOriginalNumberOfObjects()); + // DD(relabelFilter->GetSizeOfObjectsInPhysicalUnits()[0]); + // Return result typename ImageType::Pointer output = relabelFilter->GetOutput(); return output; @@ -199,6 +246,7 @@ clitk::Labelize(const ImageType * input, //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template typename ImageType::Pointer @@ -699,14 +747,11 @@ clitk::SliceBySliceSetBackgroundFromLineSeparation(typename ImageType::Pointer i siter.SetFirstDirection(0); siter.SetSecondDirection(1); siter.GoToBegin(); - uint i=0; + int i=0; typename ImageType::PointType A; typename ImageType::PointType B; typename ImageType::PointType C; - assert(lA.size() == B.size()); - // DD(lA.size()); - //DD(input->GetLargestPossibleRegion().GetSize()); - while ((iTransformIndexToPhysicalPoint(siter.GetIndex(), C); if (C[2] != lA[i][2]) { -- 2.47.1