]> Creatis software - clitk.git/blobdiff - itk/clitkSliceBySliceRelativePositionFilter.txx
Make the tool work for all image pixel types
[clitk.git] / itk / clitkSliceBySliceRelativePositionFilter.txx
index 36564cc945d9666ed672d088aceee39d6cdf59a7..eafb41608e3e8ae68f1e30b10360d5d96607e830 100644 (file)
@@ -32,6 +32,8 @@ SliceBySliceRelativePositionFilter():
 {
   SetDirection(2);
   UniqueConnectedComponentBySliceOff();
+  SetIgnoreEmptySliceObjectFlag(false);
+  this->SetCombineWithOrFlag(false);
 }
 //--------------------------------------------------------------------
 
@@ -69,7 +71,7 @@ PrintOptions()
   DD(this->GetDirection());
   DD((int)this->GetObjectBackgroundValue());
   DDV(this->GetOrientationTypeString(), (uint)this->GetNumberOfAngles());
-  DD(this->GetResampleBeforeRelativePositionFilter());
+  DD(this->GetIntermediateSpacingFlag());
   DD(this->GetIntermediateSpacing());
   DD(this->GetFuzzyThreshold());
   DD(this->GetUniqueConnectedComponentBySlice());
@@ -128,8 +130,8 @@ GenerateOutputInformation()
   if (!clitk::HaveSameSizeAndSpacing<ImageType, ImageType>(m_working_object, input)) {
     this->StartNewStep("Pad object to the same size than input");
     m_working_object = clitk::ResizeImageLike<ImageType>(m_working_object, 
-                                                          input, 
-                                                          this->GetObjectBackgroundValue());
+                                                         input, 
+                                                         this->GetObjectBackgroundValue());
     this->template StopCurrentStep<ImageType>(m_working_object);
   }
   else {
@@ -172,38 +174,41 @@ GenerateOutputInformation()
   this->StartNewStep("Perform slice by slice relative position");
   for(unsigned int i=0; i<mInputSlices.size(); i++) {
     // Select main CC in each object slice (required ?)
-    mObjectSlices[i] = Labelize<SliceType>(mObjectSlices[i], 0, true, 1);
-    mObjectSlices[i] = KeepLabels<SliceType>(mObjectSlices[i], 0, 1, 1, 1, true);
-
-    // Relative position
-    typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
-    typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
-    relPosFilter->VerboseStepFlagOff();
-    relPosFilter->WriteStepFlagOff();
-    relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
-    relPosFilter->SetBackgroundValue(this->GetBackgroundValue());
-    relPosFilter->SetInput(mInputSlices[i]); 
-    relPosFilter->SetInputObject(mObjectSlices[i]); 
-    relPosFilter->SetRemoveObjectFlag(this->GetRemoveObjectFlag());
-    for(int j=0; j<this->GetNumberOfAngles(); j++) {
-      relPosFilter->AddOrientationTypeString(this->GetOrientationTypeString(j));
-    }
-    relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag());
-    //relPosFilter->SetOrientationType(this->GetOrientationType());
-    relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing());
-    relPosFilter->SetResampleBeforeRelativePositionFilter(this->GetResampleBeforeRelativePositionFilter());
-    relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold());
-    relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
-    relPosFilter->SetCombineWithOrFlag(this->GetCombineWithOrFlag()); 
-    relPosFilter->Update();
-    mInputSlices[i] = relPosFilter->GetOutput();
-
-    // Select main CC if needed
-    if (GetUniqueConnectedComponentBySlice()) {
-      mInputSlices[i] = Labelize<SliceType>(mInputSlices[i], 0, true, 1);
-      mInputSlices[i] = KeepLabels<SliceType>(mInputSlices[i], 0, 1, 1, 1, true);
-    }
+    int nb=0;
+    mObjectSlices[i] = LabelizeAndCountNumberOfObjects<SliceType>(mObjectSlices[i], 0, true, 1, nb);
+    if ((!GetIgnoreEmptySliceObjectFlag()) || (nb!=0)) {
+      mObjectSlices[i] = KeepLabels<SliceType>(mObjectSlices[i], 0, 1, 1, 1, true);
+
+      // Relative position
+      typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
+      typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
+
+      relPosFilter->VerboseStepFlagOff();
+      relPosFilter->WriteStepFlagOff();
+      relPosFilter->SetBackgroundValue(this->GetBackgroundValue());
+      relPosFilter->SetInput(mInputSlices[i]); 
+      relPosFilter->SetInputObject(mObjectSlices[i]); 
+      relPosFilter->SetRemoveObjectFlag(this->GetRemoveObjectFlag());
+      for(int j=0; j<this->GetNumberOfAngles(); j++) {
+        relPosFilter->AddOrientationTypeString(this->GetOrientationTypeString(j));
+      }
+      relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag());
+      //relPosFilter->SetOrientationType(this->GetOrientationType());
+      relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing());
+      relPosFilter->SetIntermediateSpacingFlag(this->GetIntermediateSpacingFlag());
+      relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold());
+      relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
+      relPosFilter->SetCombineWithOrFlag(this->GetCombineWithOrFlag()); 
+      relPosFilter->Update();
+      mInputSlices[i] = relPosFilter->GetOutput();
+
+      // Select main CC if needed
+      if (GetUniqueConnectedComponentBySlice()) {
+        mInputSlices[i] = Labelize<SliceType>(mInputSlices[i], 0, true, 1);
+        mInputSlices[i] = KeepLabels<SliceType>(mInputSlices[i], 0, 1, 1, 1, true);
+      }
 
+    }
   }
 
   // Join the slices