]> Creatis software - clitk.git/commitdiff
binarize
authordsarrut <dsarrut>
Sat, 6 Feb 2010 15:38:13 +0000 (15:38 +0000)
committerdsarrut <dsarrut>
Sat, 6 Feb 2010 15:38:13 +0000 (15:38 +0000)
filters/clitkBinarizeImage.ggo
filters/clitkBinarizeImageGenericFilter.txx
vv/qt_ui/vvToolBinarize.ui
vv/vvMainWindow.cxx
vv/vvToolBinarize.cxx
vv/vvToolBinarize.h

index 5e56844fb57fde676a1e3b8c31f0b1b6495b2255..c4620da18f96111e0ba685745c6d2da2d2088feb 100644 (file)
@@ -15,5 +15,4 @@ option "upper"        u       "Upper intensity (default=max), fg is lower than this va
 
 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
+option "mode"          -       "Use FG and/or BG values (if FG, the BG is replaced by the input image values)" values="FG","BG","both"  default="both" no
index 6d8d4e7b7d0e5622d3fbea866a7bb89730f3f568..80837bd05900ac59d4351bac0e4672c8e7cf9873 100644 (file)
@@ -70,33 +70,16 @@ 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;
+    typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
 
     // Filter
     typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
     typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
     thresholdFilter->SetInput(input);
-
-    /*    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;
-       }*/
-
+    thresholdFilter->SetInsideValue(mArgsInfo.fg_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));
 
@@ -104,41 +87,36 @@ namespace clitk
     DD(mArgsInfo.upper_given);
     DD(mArgsInfo.lower_arg);
     DD(mArgsInfo.upper_arg);
-
     DD(mArgsInfo.fg_arg);
     DD(mArgsInfo.bg_arg);
     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);
-
-    thresholdFilter->Update();
-
-    // If no BG or no FG : new image, copy input with MaskImageFilter
-    // If setFG -> FG BG have been changed
-    if (mArgsInfo.useBG_flag && mArgsInfo.useFG_flag) {
+    DD(mArgsInfo.mode_arg);
+
+    /* Three modes : 
+       - FG -> only use FG value for pixel in the Foreground (or Inside), keep input values for outside
+       - BG -> only use BG value for pixel in the Background (or Outside), keep input values for inside
+       - both -> use FG and BG (real binary image)
+    */
+      if (mArgsInfo.mode_arg == std::string("both")) {
+      thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
+      thresholdFilter->Update();
       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");
+      thresholdFilter->SetOutsideValue(0);
+      if (mArgsInfo.mode_arg == std::string("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);
+       maskFilter->Update();
        outputImage = maskFilter->GetOutput();
       }
       else {
-       DD("use FG");
        typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
        typename maskFilterType::Pointer maskFilter = maskFilterType::New();
        maskFilter->SetInput1(input);
index 3b9a1f0f2675d8b9bdcf320444a832d4e70ac8e2..8e110fbd6d9be15ad8270852975bdf5bb25c4e02 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>320</width>
-    <height>298</height>
+    <width>405</width>
+    <height>285</height>
    </rect>
   </property>
   <property name="windowTitle">
        <item>
         <layout class="QVBoxLayout" name="verticalLayout_3">
          <item>
-          <layout class="QHBoxLayout" name="horizontalLayout">
-           <item>
-            <layout class="QVBoxLayout" name="verticalLayout">
-             <item>
-              <widget class="QFrame" name="frame">
-               <property name="frameShape">
-                <enum>QFrame::StyledPanel</enum>
-               </property>
-               <property name="frameShadow">
-                <enum>QFrame::Raised</enum>
-               </property>
-               <layout class="QVBoxLayout" name="verticalLayout_5">
-                <item>
-                 <widget class="QRadioButton" name="mRadioButtonGreaterThan">
-                  <property name="text">
-                   <string>Greater than</string>
-                  </property>
-                  <property name="checked">
-                   <bool>true</bool>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QRadioButton" name="mRadioButtonEqualThan">
-                  <property name="text">
-                   <string>Equal</string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QRadioButton" name="radioButton_3">
-                  <property name="text">
-                   <string>Not equal</string>
-                  </property>
-                 </widget>
-                </item>
-               </layout>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item>
-            <widget class="vvIntensityValueSlider" name="mThresholdSlider1" native="true"/>
-           </item>
-          </layout>
-         </item>
-         <item>
-          <layout class="QHBoxLayout" name="horizontalLayout_2">
-           <item>
+          <layout class="QGridLayout" name="gridLayout_2">
+           <item row="2" column="1">
             <widget class="QRadioButton" name="mRadioButtonLowerThan">
              <property name="text">
-              <string>Lower than</string>
+              <string>and lower than</string>
              </property>
              <property name="autoExclusive">
               <bool>false</bool>
              </property>
             </widget>
            </item>
-           <item>
+           <item row="2" column="2">
             <widget class="vvIntensityValueSlider" name="mThresholdSlider2" native="true">
              <property name="enabled">
               <bool>false</bool>
              </property>
             </widget>
            </item>
+           <item row="1" column="1">
+            <widget class="QLabel" name="label_2">
+             <property name="text">
+              <string>Foreground (FG) is greater than : </string>
+             </property>
+            </widget>
+           </item>
+           <item row="1" column="2">
+            <widget class="vvIntensityValueSlider" name="mThresholdSlider1" native="true"/>
+           </item>
           </layout>
          </item>
         </layout>
     </hint>
    </hints>
   </connection>
-  <connection>
-   <sender>mRadioButtonEqualThan</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>mRadioButtonLowerThan</receiver>
-   <slot>setDisabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>82</x>
-     <y>70</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>88</x>
-     <y>129</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>radioButton_3</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>mRadioButtonLowerThan</receiver>
-   <slot>setDisabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>73</x>
-     <y>90</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>137</x>
-     <y>129</y>
-    </hint>
-   </hints>
-  </connection>
   <connection>
    <sender>mCheckBoxUseBG</sender>
    <signal>toggled(bool)</signal>
      <y>203</y>
     </hint>
     <hint type="destinationlabel">
-     <x>202</x>
-     <y>204</y>
+     <x>395</x>
+     <y>225</y>
     </hint>
    </hints>
   </connection>
index dab9aaf39ed7cdb442e81457b37c5864e2a3977a..2cb28703e381aa1d6600aae56ca0170f90e3e07a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvMainWindow.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/02/05 09:06:46 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2010/02/06 15:38:13 $
+  Version:   $Revision: 1.7 $
   Author :   Pierre Seroul (pierre.seroul@gmail.com)
 
   Copyright (C) 200COLUMN_IMAGE_NAME
@@ -118,7 +118,7 @@ vvMainWindow::vvMainWindow() {
                                                         tr("Open new Image"));
   connect(actionOpen_new_image,SIGNAL(triggered()),this,SLOT(OpenImages()));
   contextActions.push_back(actionOpen_new_image);
-
+  actionOpen_new_image->setShortcut("Ctrl+O");//Qt::CTRL & Qt::Key_O);
   contextMenu.addSeparator();
 
   QAction* actionClose_Image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")),
index 251c0d68607cd4da37a300d0e406f3b147d0c0dd..c5f209de7e161434fac593b755f8e06aabdfbae4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolBinarize.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/02/03 13:08:55 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2010/02/06 15:38:14 $
+  Version:   $Revision: 1.5 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2008
@@ -61,8 +61,9 @@ vvToolBinarize::vvToolBinarize(QWidget * parent, Qt::WindowFlags f)
   connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
   connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1(double)));
   connect(mThresholdSlider2, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT2(double)));
-
   connect(mRadioButtonLowerThan, SIGNAL(toggled(bool)), this, SLOT(enableLowerThan(bool)));
+  connect(mCheckBoxUseFG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool)));
+  connect(mCheckBoxUseBG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool)));
 
   // VTK objects
   mClipper = vtkImageClip::New();
@@ -76,6 +77,7 @@ vvToolBinarize::vvToolBinarize(QWidget * parent, Qt::WindowFlags f)
   mFGSlider->SetText("Foreground value");
   mBGSlider->SetText("Background value");
 
+
   // Disable main widget while input image is not selected
   toolMainWidget->setEnabled(false);
 
@@ -106,6 +108,15 @@ void vvToolBinarize::enableLowerThan(bool b) {
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolBinarize::useFGBGtoggled(bool) {
+  DD("ici");
+  if (!mCheckBoxUseBG->isChecked() && !mCheckBoxUseFG->isChecked()) 
+    mCheckBoxUseBG->toggle();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvToolBinarize::InputIsSelected() {
 
@@ -120,9 +131,13 @@ void vvToolBinarize::InputIsSelected() {
   mThresholdSlider2->SetImage(mCurrentImage);
   mFGSlider->SetImage(mCurrentImage);
   mBGSlider->SetImage(mCurrentImage);
+  DD(mCurrentSliceManager->GetFileName().c_str());
+  mFGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
+  mFGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
+  mBGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
+  mBGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
   mFGSlider->SetValue(1);
   mBGSlider->SetValue(0);
-  DD(mCurrentSliceManager->GetFileName().c_str());
   
   DD("VTK");
   DD(mCurrentSliceManager->NumberOfSlicers());
@@ -238,7 +253,7 @@ void vvToolBinarize::GetArgsInfoFromGUI() {
   mArgsInfo.lower_given = 0;
   bool inverseBGandFG = false;
 
-  if (mRadioButtonGreaterThan->isChecked()) { // Greater Than (and Lower Than)
+  // if (mRadioButtonGreaterThan->isChecked()) { // Greater Than (and Lower Than)
     mArgsInfo.lower_given = 1;
     mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
     DD(mArgsInfo.lower_arg);
@@ -250,22 +265,22 @@ void vvToolBinarize::GetArgsInfoFromGUI() {
         DD("TODO : lower thres greater than greater thres ! Ignoring ");
       }
     }
-  }
-  else {
-    if (mRadioButtonEqualThan->isChecked()) {
-      mArgsInfo.lower_given = 1;
-      mArgsInfo.upper_given = 1;
-      mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
-      mArgsInfo.upper_arg = mThresholdSlider1->GetValue();
-    }
-    else {
-      mArgsInfo.lower_given = 1;
-      mArgsInfo.upper_given = 1;
-      mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
-      mArgsInfo.upper_arg = mThresholdSlider1->GetValue();
-      inverseBGandFG = true;
-    }
-  }
+  // }
+  // else {
+  //   if (mRadioButtonEqualThan->isChecked()) {
+  //     mArgsInfo.lower_given = 1;
+  //     mArgsInfo.upper_given = 1;
+  //     mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
+  //     mArgsInfo.upper_arg = mThresholdSlider1->GetValue();
+  //   }
+  //   else {
+  //     mArgsInfo.lower_given = 1;
+  //     mArgsInfo.upper_given = 1;
+  //     mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
+  //     mArgsInfo.upper_arg = mThresholdSlider1->GetValue();
+  //     inverseBGandFG = true;
+  //   }
+  // }
 
   mArgsInfo.fg_arg = mFGSlider->GetValue();
   mArgsInfo.bg_arg = mBGSlider->GetValue();
@@ -278,11 +293,14 @@ void vvToolBinarize::GetArgsInfoFromGUI() {
   mArgsInfo.fg_given = 1;
   mArgsInfo.bg_given = 1;
 
-  mArgsInfo.useBG_flag = mCheckBoxUseBG->isChecked();
-  mArgsInfo.useFG_flag = mCheckBoxUseFG->isChecked();
+  if (mCheckBoxUseBG->isChecked()) {
+    if (mCheckBoxUseFG->isChecked()) mArgsInfo.mode_arg = (char*)"both";
+    else mArgsInfo.mode_arg = (char*)"BG";
+  }
+  else mArgsInfo.mode_arg = (char*)"FG";
 
-  DD(mArgsInfo.useBG_flag);
-  DD(mArgsInfo.useFG_flag);
+  // DD(mArgsInfo.useBG_flag);
+  // DD(mArgsInfo.useFG_flag);
 
   mArgsInfo.verbose_flag = true;
 
index af85929842123a042f6b13f3cdcfce20849ceba5..b40b267cfbc764cb33b05ec6893afd108027aae8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   vv
   Module:    $RCSfile: vvToolBinarize.h,v $
   Language:  C++
-  Date:      $Date: 2010/02/05 09:06:46 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2010/02/06 15:38:14 $
+  Version:   $Revision: 1.3 $
   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
 
   Copyright (C) 2010
@@ -79,6 +79,7 @@ class vvToolBinarize:
   void UpdateSlice(int slicer,int slices);
   void InputIsSelected();
   void enableLowerThan(bool b);
+  void useFGBGtoggled(bool);
 
  protected:
   Ui::vvToolBinarize ui;