From 71d769c28f63906bc4872127e4d2d4b7b9f8e5ed Mon Sep 17 00:00:00 2001 From: dsarrut Date: Sat, 6 Feb 2010 15:38:13 +0000 Subject: [PATCH] binarize --- filters/clitkBinarizeImage.ggo | 3 +- filters/clitkBinarizeImageGenericFilter.txx | 54 +++------- vv/qt_ui/vvToolBinarize.ui | 105 ++++---------------- vv/vvMainWindow.cxx | 6 +- vv/vvToolBinarize.cxx | 68 ++++++++----- vv/vvToolBinarize.h | 5 +- 6 files changed, 84 insertions(+), 157 deletions(-) diff --git a/filters/clitkBinarizeImage.ggo b/filters/clitkBinarizeImage.ggo index 5e56844..c4620da 100644 --- a/filters/clitkBinarizeImage.ggo +++ b/filters/clitkBinarizeImage.ggo @@ -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 diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx index 6d8d4e7..80837bd 100644 --- a/filters/clitkBinarizeImageGenericFilter.txx +++ b/filters/clitkBinarizeImageGenericFilter.txx @@ -70,33 +70,16 @@ namespace clitk // Reading input typename InputImageType::Pointer input = this->template GetInput(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(input); - return; - } - // Main filter typedef typename InputImageType::PixelType PixelType; - typedef itk::Image OutputImageType; + typedef itk::Image OutputImageType; // Filter typedef itk::BinaryThresholdImageFilter 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(mArgsInfo.lower_arg)); if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(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(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 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 maskFilterType; typename maskFilterType::Pointer maskFilter = maskFilterType::New(); maskFilter->SetInput1(input); diff --git a/vv/qt_ui/vvToolBinarize.ui b/vv/qt_ui/vvToolBinarize.ui index 3b9a1f0..8e110fb 100644 --- a/vv/qt_ui/vvToolBinarize.ui +++ b/vv/qt_ui/vvToolBinarize.ui @@ -6,8 +6,8 @@ 0 0 - 320 - 298 + 405 + 285 @@ -28,71 +28,34 @@ - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Greater than - - - true - - - - - - - Equal - - - - - - - Not equal - - - - - - - - - - - - - - - - + + - Lower than + and lower than false - + false + + + + Foreground (FG) is greater than : + + + + + + @@ -215,38 +178,6 @@ - - mRadioButtonEqualThan - toggled(bool) - mRadioButtonLowerThan - setDisabled(bool) - - - 82 - 70 - - - 88 - 129 - - - - - radioButton_3 - toggled(bool) - mRadioButtonLowerThan - setDisabled(bool) - - - 73 - 90 - - - 137 - 129 - - - mCheckBoxUseBG toggled(bool) @@ -258,8 +189,8 @@ 203 - 202 - 204 + 395 + 225 diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index dab9aaf..2cb2870 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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")), diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx index 251c0d6..c5f209d 100644 --- a/vv/vvToolBinarize.cxx +++ b/vv/vvToolBinarize.cxx @@ -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; diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index af85929..b40b267 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -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; -- 2.47.1