]> Creatis software - clitk.git/commitdiff
- binarize filter (allow no use of FG/BG)
authordsarrut <dsarrut>
Wed, 3 Feb 2010 10:54:58 +0000 (10:54 +0000)
committerdsarrut <dsarrut>
Wed, 3 Feb 2010 10:54:58 +0000 (10:54 +0000)
filters/clitkBinarizeImage.ggo
filters/clitkBinarizeImageGenericFilter.h
filters/clitkBinarizeImageGenericFilter.txx
filters/clitkGuerreroVentilationGenericFilter.cxx

index 41701b60fe9639ac08a18a5449f434540ecd8df6..5e56844fb57fde676a1e3b8c31f0b1b6495b2255 100644 (file)
@@ -1,5 +1,5 @@
 #File clitkBinarizeImage.ggo
-Package "clitkBinarizeImage"
+package "clitkBinarizeImage"
 version "1.0"
 purpose ""
 
@@ -10,10 +10,10 @@ option "imagetypes"         -       "Display allowed image types"     flag          off
 
 option "input"         i       "Input image filename"            string        yes
 option "output"        o       "Output image filename"           string        yes
-option "lower"         l       "Lower intensity (default=min)"   double        no
-option "upper"         u       "Upper intensity (default=max)"   double        no
-option "fg"                    -       "Foreground (FG) value"           double        no      default="1"
-option "bg"                    -       "Background (BG) value"           double        no      default="0"
-option "setBG"                 -       "No FG, keep values from input"   flag          off
-option "setFG"                 -       "No BG, keep values from input"   flag          off
+option "lower"         l       "Lower intensity (default=min), fg is greater than this value"    double        no
+option "upper"         u       "Upper intensity (default=max), fg is lower than this value"      double        no
 
+option "fg"                    -       "Foreground (FG) or 'inside' value"               double        no      default="1"
+option "bg"                    -       "Background (BG) or 'ouside' value"               double        no      default="0"
+option "useFG"                 -       "Use FG value (if not keep values from input)"    flag          off
+option "useBG"                 -       "Use BG value (if not keep values from input)"    flag          off
index f35bc7a650a6d9ce2a9011b24be9156ff5e0e104..ad2966d92a3f00723d1a9f65229f8f1ef175157f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   clitk
   Module:    $RCSfile: clitkBinarizeImageGenericFilter.h,v $
   Language:  C++
-  Date:      $Date: 2010/01/29 07:28:33 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/02/03 10:54:58 $
+  Version:   $Revision: 1.2 $
   Author :   Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
              David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
 #include "clitkCommon.h"
 #include "clitkImageToImageGenericFilter.h"
 
-// itk include
-#include "itkBinaryThresholdImageFilter.h"
-
-// std include
-#include <map>
-
 //--------------------------------------------------------------------
 namespace clitk 
 {
index 6b993e56ae97e7f73656a29e615823013150d847..6d8d4e7b7d0e5622d3fbea866a7bb89730f3f568 100644 (file)
  * 
  ===================================================*/
 
+// itk include
+#include "itkBinaryThresholdImageFilter.h"
 #include "itkMaskImageFilter.h"
+#include "itkMaskNegatedImageFilter.h"
 
 namespace clitk
 {
@@ -66,7 +69,15 @@ namespace clitk
 
     // Reading input
     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
-    
+
+    // Check option
+    if (!mArgsInfo.useFG_flag && !mArgsInfo.useBG_flag) {
+      // Do nothing !!
+      std::cerr << "Warning : FG and BG are not used ! Do nothing." << std::endl;
+      this->template SetNextOutput<InputImageType>(input);
+      return;
+    }
+
     // Main filter
     typedef typename InputImageType::PixelType PixelType;
     typedef itk::Image<int, InputImageType::ImageDimension> OutputImageType;
@@ -76,14 +87,18 @@ namespace clitk
     typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
     thresholdFilter->SetInput(input);
 
-    if (mArgsInfo.setFG_flag) {
-      double fg = mArgsInfo.fg_arg;
-      mArgsInfo.fg_arg = mArgsInfo.bg_arg;
-      mArgsInfo.bg_arg = fg;
-    }
+    /*    if (mArgsInfo.useFG_flag && !mArgsInfo.useBG_flag) {
+      DD("inverse");
+      // double fg = mArgsInfo.fg_arg;
+      //mArgsInfo.fg_arg = mArgsInfo.bg_arg;
+      // mArgsInfo.bg_arg = fg;
+       //   bool lo = mArgsInfo.lower_given;
+       //mArgsInfo.lower_given = mArgsInfo.upper_given;
+       //mArgsInfo.upper_given = lo;
+       }*/
 
-    if(mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
-    if(mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
+    if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
+    if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
 
     DD(mArgsInfo.lower_given);
     DD(mArgsInfo.upper_given);
@@ -95,6 +110,9 @@ namespace clitk
     DD(mArgsInfo.fg_given);
     DD(mArgsInfo.bg_given);
 
+    DD(mArgsInfo.useFG_flag);
+    DD(mArgsInfo.useBG_flag);
+
     thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
     thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
 
@@ -102,25 +120,36 @@ namespace clitk
 
     // If no BG or no FG : new image, copy input with MaskImageFilter
     // If setFG -> FG BG have been changed
-    if (0) {
-      if (mArgsInfo.setBG_flag || mArgsInfo.setFG_flag) {
-        DD("set BG!!!!");
-        //if ()
-        typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
-        typename maskFilterType::Pointer maskFilter = maskFilterType::New();
-        maskFilter->SetInput1(input);
-        maskFilter->SetInput2(thresholdFilter->GetOutput());
-        maskFilter->Update();
-        typename InputImageType::Pointer outputImage = maskFilter->GetOutput();
-        // Write/Save results
-        this->template SetNextOutput<InputImageType>(outputImage);
-      }
-    }
-    else {
+    if (mArgsInfo.useBG_flag && mArgsInfo.useFG_flag) {
       typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
       // Write/Save results
       this->template SetNextOutput<OutputImageType>(outputImage);
     }
+    else {
+      typename InputImageType::Pointer outputImage;
+      if (mArgsInfo.useBG_flag) {
+       DD("use BG");
+       typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
+       typename maskFilterType::Pointer maskFilter = maskFilterType::New();
+       maskFilter->SetInput1(input);
+       maskFilter->SetInput2(thresholdFilter->GetOutput());
+       maskFilter->Update();
+       maskFilter->SetOutsideValue(mArgsInfo.bg_arg);
+       outputImage = maskFilter->GetOutput();
+      }
+      else {
+       DD("use FG");
+       typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
+       typename maskFilterType::Pointer maskFilter = maskFilterType::New();
+       maskFilter->SetInput1(input);
+       maskFilter->SetInput2(thresholdFilter->GetOutput());
+       maskFilter->SetOutsideValue(mArgsInfo.fg_arg);
+       maskFilter->Update();
+       outputImage = maskFilter->GetOutput();
+      }
+      // Write/Save results
+      this->template SetNextOutput<InputImageType>(outputImage);
+    }
   }
   //--------------------------------------------------------------------
 
index 47a0359bb48841ffff51a0081fd39ffe5fbfec8a..1a2dcd66e74155daf09c5723165409d38cff9127 100644 (file)
@@ -20,6 +20,7 @@
  -------------------------------------------------------------------*/
 
 #include <sstream>
+#include <vector>
 #include "clitkGuerreroVentilationGenericFilter.h"
 #include <itkBinaryGuerreroFilter.h>
 #include <itkImageDuplicator.h>