]> Creatis software - clitk.git/commitdiff
Add LabelizeAndCountNumberOfObjects
authordsarrut <dsarrut>
Tue, 22 Feb 2011 07:12:02 +0000 (07:12 +0000)
committerdsarrut <dsarrut>
Tue, 22 Feb 2011 07:12:02 +0000 (07:12 +0000)
itk/clitkSegmentationUtils.h
itk/clitkSegmentationUtils.txx

index 7308b7a507958581b3ec1ee8d21cc2026f0ebba4..aafe7220aa31e3072907dfc52ed5bf89b3ea4166 100644 (file)
@@ -74,6 +74,13 @@ namespace clitk {
            typename TImageType::PixelType BG, 
            bool isFullyConnected, 
            int minimalComponentSize);
+  template<class TImageType>
+  typename TImageType::Pointer
+  LabelizeAndCountNumberOfObjects(const TImageType * input, 
+                                  typename TImageType::PixelType BG, 
+                                  bool isFullyConnected, 
+                                  int minimalComponentSize, 
+                                  int & nb);
   //--------------------------------------------------------------------
 
 
index dccfc35df72daee8087047b54757168e1909ed46..c8f976e69449f2d95456e1a9c1a3a1c6d4e77064 100644 (file)
@@ -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<class ImageType>
+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<int, ImageType::ImageDimension> InternalImageType;
+  
+  // Connected Component label 
+  typedef itk::ConnectedComponentImageFilter<ImageType, InternalImageType> 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<InternalImageType, ImageType> 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<class ImageType>
 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 ((i<lA.size()) && (!siter.IsAtEnd())) {
+  while (!siter.IsAtEnd()) {
     // Check that the current slice correspond to the current point
     input->TransformIndexToPhysicalPoint(siter.GetIndex(), C);
     if (C[2] != lA[i][2]) {