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
// 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));
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);
<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>
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
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")),
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
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();
mFGSlider->SetText("Foreground value");
mBGSlider->SetText("Background value");
+
// Disable main widget while input image is not selected
toolMainWidget->setEnabled(false);
//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+void vvToolBinarize::useFGBGtoggled(bool) {
+ DD("ici");
+ if (!mCheckBoxUseBG->isChecked() && !mCheckBoxUseFG->isChecked())
+ mCheckBoxUseBG->toggle();
+}
+//------------------------------------------------------------------------------
+
+
//------------------------------------------------------------------------------
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());
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);
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();
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;
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
void UpdateSlice(int slicer,int slices);
void InputIsSelected();
void enableLowerThan(bool b);
+ void useFGBGtoggled(bool);
protected:
Ui::vvToolBinarize ui;