From 2b7d488baad476881e322f58ceab4669ebe961f9 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 3 Feb 2010 10:54:58 +0000 Subject: [PATCH] - binarize filter (allow no use of FG/BG) --- filters/clitkBinarizeImage.ggo | 14 ++-- filters/clitkBinarizeImageGenericFilter.h | 10 +-- filters/clitkBinarizeImageGenericFilter.txx | 75 +++++++++++++------ .../clitkGuerreroVentilationGenericFilter.cxx | 1 + 4 files changed, 62 insertions(+), 38 deletions(-) diff --git a/filters/clitkBinarizeImage.ggo b/filters/clitkBinarizeImage.ggo index 41701b6..5e56844 100644 --- a/filters/clitkBinarizeImage.ggo +++ b/filters/clitkBinarizeImage.ggo @@ -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 diff --git a/filters/clitkBinarizeImageGenericFilter.h b/filters/clitkBinarizeImageGenericFilter.h index f35bc7a..ad2966d 100644 --- a/filters/clitkBinarizeImageGenericFilter.h +++ b/filters/clitkBinarizeImageGenericFilter.h @@ -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 David Sarrut (david.sarrut@creatis.insa-lyon.fr) @@ -34,12 +34,6 @@ #include "clitkCommon.h" #include "clitkImageToImageGenericFilter.h" -// itk include -#include "itkBinaryThresholdImageFilter.h" - -// std include -#include - //-------------------------------------------------------------------- namespace clitk { diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx index 6b993e5..6d8d4e7 100644 --- a/filters/clitkBinarizeImageGenericFilter.txx +++ b/filters/clitkBinarizeImageGenericFilter.txx @@ -10,7 +10,10 @@ * ===================================================*/ +// 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(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; @@ -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(mArgsInfo.lower_arg)); - if(mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(mArgsInfo.upper_arg)); + if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast(mArgsInfo.lower_arg)); + if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(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 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(outputImage); - } - } - else { + if (mArgsInfo.useBG_flag && mArgsInfo.useFG_flag) { 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"); + typedef itk::MaskImageFilter 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 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(outputImage); + } } //-------------------------------------------------------------------- diff --git a/filters/clitkGuerreroVentilationGenericFilter.cxx b/filters/clitkGuerreroVentilationGenericFilter.cxx index 47a0359..1a2dcd6 100644 --- a/filters/clitkGuerreroVentilationGenericFilter.cxx +++ b/filters/clitkGuerreroVentilationGenericFilter.cxx @@ -20,6 +20,7 @@ -------------------------------------------------------------------*/ #include +#include #include "clitkGuerreroVentilationGenericFilter.h" #include #include -- 2.47.1