]> Creatis software - clitk.git/commitdiff
new tool to normalize an image
authorBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Thu, 9 Jan 2014 13:43:47 +0000 (14:43 +0100)
committerBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Thu, 9 Jan 2014 13:43:47 +0000 (14:43 +0100)
tools/CMakeLists.txt
tools/clitkNormalizeImageFilter.cxx [new file with mode: 0644]
tools/clitkNormalizeImageFilter.ggo [new file with mode: 0644]
tools/clitkNormalizeImageFilterGenericFilter.h [new file with mode: 0644]
tools/clitkNormalizeImageFilterGenericFilter.txx [new file with mode: 0644]

index 478b8173b76f8d8ac1fcfdd7353caade239b11e4..3e7a20bb69ba9a7d9b2aa765d2ae638373410a3e 100644 (file)
@@ -300,6 +300,11 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkImageUncertainty clitkCommon ${ITK_LIBRARIES})
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageUncertainty)
 
+  WRAP_GGO(clitkNormalizeImageFilter_GGO_C clitkNormalizeImageFilter.ggo)
+  ADD_EXECUTABLE(clitkNormalizeImageFilter clitkNormalizeImageFilter.cxx ${clitkNormalizeImageFilter_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkNormalizeImageFilter clitkCommon )
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkNormalizeImageFilter)
+
   WRAP_GGO(clitkImageGradientMagnitude_GGO_C clitkImageGradientMagnitude.ggo)
   ADD_EXECUTABLE(clitkImageGradientMagnitude clitkImageGradientMagnitude.cxx ${clitkImageGradientMagnitude_GGO_C})
   TARGET_LINK_LIBRARIES(clitkImageGradientMagnitude clitkCommon )
diff --git a/tools/clitkNormalizeImageFilter.cxx b/tools/clitkNormalizeImageFilter.cxx
new file mode 100644 (file)
index 0000000..071aa4d
--- /dev/null
@@ -0,0 +1,50 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+/* =================================================
+ * @file   clitkNormalizeImageFilterGenericFilter.txx
+ * @author xxx <xxx@creatis.insa-lyon.fr>
+ * @date   29 June 2029
+ *
+ * @brief NormalizeImageFilter an image
+ *
+ ===================================================*/
+
+// clitk
+#include "clitkNormalizeImageFilter_ggo.h"
+#include "clitkNormalizeImageFilterGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkNormalizeImageFilter, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::NormalizeImageFilterGenericFilter<args_info_clitkNormalizeImageFilter> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+  filter->Update();
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitkNormalizeImageFilter.ggo b/tools/clitkNormalizeImageFilter.ggo
new file mode 100644 (file)
index 0000000..b67e3b8
--- /dev/null
@@ -0,0 +1,13 @@
+#File clitkNormalizeImageFilter.ggo
+package "clitkNormalizeImageFilter"
+version "1.0"
+purpose ""
+
+option "config"                -       "Config file"                     string        optional
+option "verbose"       v       "Verbose"                         flag          off
+
+option "imagetypes"    -       "Display allowed image types"     flag          off
+
+option "input"         i       "Input image filename"            string        required
+option "output"        o       "Output image filename"           string        required
+option "mask"          m       "Mask input image filename"       string        optional
diff --git a/tools/clitkNormalizeImageFilterGenericFilter.h b/tools/clitkNormalizeImageFilterGenericFilter.h
new file mode 100644 (file)
index 0000000..85f28e4
--- /dev/null
@@ -0,0 +1,69 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef CLITKNormalizeImageFilterGENERICFILTER_H
+#define CLITKNormalizeImageFilterGENERICFILTER_H
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+template<class args_info_type>
+class ITK_EXPORT NormalizeImageFilterGenericFilter:
+        public ImageToImageGenericFilter<NormalizeImageFilterGenericFilter<args_info_type> >
+{
+
+public:
+
+    //--------------------------------------------------------------------
+    NormalizeImageFilterGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef NormalizeImageFilterGenericFilter         Self;
+    typedef itk::SmartPointer<Self>                   Pointer;
+    typedef itk::SmartPointer<const Self>             ConstPointer;
+
+    //--------------------------------------------------------------------
+    // Method for creation through the object factory
+    // and Run-time type information (and related methods)
+    itkNewMacro(Self);
+    itkTypeMacro(NormalizeImageFilterGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type & a);
+
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class InputImageType>
+    void UpdateWithInputImageType();
+
+protected:
+    template<unsigned int Dim> void InitializeImageType();
+    args_info_type mArgsInfo;
+
+}; // end class
+//--------------------------------------------------------------------
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkNormalizeImageFilterGenericFilter.txx"
+#endif
+
+#endif // #define clitkNormalizeImageFilterGenericFilter_h
diff --git a/tools/clitkNormalizeImageFilterGenericFilter.txx b/tools/clitkNormalizeImageFilterGenericFilter.txx
new file mode 100644 (file)
index 0000000..99a43a4
--- /dev/null
@@ -0,0 +1,165 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef clitkNormalizeImageFilterGenericFilter_txx
+#define clitkNormalizeImageFilterGenericFilter_txx
+
+/* =================================================
+ * @file   clitkNormalizeImageFilterGenericFilter.txx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ *
+ * @brief
+ *
+ ===================================================*/
+
+// itk include
+#include "itkLabelStatisticsImageFilter.h"
+#include "itkMaskImageFilter.h"
+#include "itkMaskNegatedImageFilter.h"
+#include <clitkCommon.h>
+
+namespace clitk
+{
+
+    //--------------------------------------------------------------------
+    template<class args_info_type>
+    NormalizeImageFilterGenericFilter<args_info_type>::NormalizeImageFilterGenericFilter():
+        ImageToImageGenericFilter<Self>("NormalizeImageFilter")
+    {
+        InitializeImageType<2>();
+        InitializeImageType<3>();
+    }
+    //--------------------------------------------------------------------
+
+
+    //--------------------------------------------------------------------
+    template<class args_info_type>
+    template<unsigned int Dim>
+    void NormalizeImageFilterGenericFilter<args_info_type>::InitializeImageType()
+    {
+        ADD_DEFAULT_IMAGE_TYPES(Dim);
+    }
+    //--------------------------------------------------------------------
+
+
+    //--------------------------------------------------------------------
+    template<class args_info_type>
+    void NormalizeImageFilterGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
+    {
+        mArgsInfo=a;
+        this->SetIOVerbose(mArgsInfo.verbose_flag);
+        if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+
+        if (mArgsInfo.input_given) {
+            this->SetInputFilename(mArgsInfo.input_arg);
+        }
+        if (mArgsInfo.output_given) {
+            this->SetOutputFilename(mArgsInfo.output_arg);
+        }
+        if (mArgsInfo.mask_given) {
+            this->AddInputFilename(mArgsInfo.mask_arg);
+        }
+    }
+    //--------------------------------------------------------------------
+
+    //--------------------------------------------------------------------
+    // Update with the number of dimensions and the pixeltype
+    //--------------------------------------------------------------------
+    template<class args_info_type>
+    template<class InputImageType>
+    void
+    NormalizeImageFilterGenericFilter<args_info_type>::UpdateWithInputImageType()
+    {
+
+        // Main filter
+        typedef typename InputImageType::PixelType InputPixelType;
+        typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
+        typedef itk::Image<unsigned char, OutputImageType::ImageDimension> MaskImageType;
+
+        // Reading input
+        typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+
+        typename MaskImageType::Pointer mask = NULL;
+        if(mArgsInfo.mask_given) {
+            mask = this->template GetInput<MaskImageType>(1);
+        }
+        else {
+            mask = MaskImageType::New();
+            mask->SetRegions(input->GetLargestPossibleRegion());
+            mask->SetOrigin(input->GetOrigin());
+            mask->SetSpacing(input->GetSpacing());
+            mask->Allocate();
+            mask->FillBuffer(1);
+        }
+
+        // Create output image
+        typename OutputImageType::Pointer outputImage = OutputImageType::New();
+        outputImage->SetRegions(input->GetLargestPossibleRegion());
+        outputImage->SetOrigin(input->GetOrigin());
+        outputImage->SetSpacing(input->GetSpacing());
+        outputImage->Allocate();
+        outputImage->FillBuffer(0.0);
+        // Set output iterator
+        typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
+        IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
+
+        // Filter
+        // Set iterator
+        typedef itk::ImageRegionIterator<InputImageType> IteratorType;
+        IteratorType it(input, input->GetLargestPossibleRegion());
+
+        // Set mask iterator
+        typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
+        IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
+
+        typedef itk::LabelStatisticsImageFilter< InputImageType, MaskImageType > LabelStatisticsImageFilterType;
+        typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
+        labelStatisticsImageFilter->SetLabelInput( mask );
+        labelStatisticsImageFilter->SetInput(input);
+        labelStatisticsImageFilter->Update();
+
+        //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl;
+
+        float minImg = labelStatisticsImageFilter->GetMinimum(1);
+        //std::cout << "minImg= " << minImg << std::endl;
+        float maxImg = labelStatisticsImageFilter->GetMaximum(1);
+        //std::cout << "maxImg= " << maxImg << std::endl;
+
+        it.GoToBegin();
+        ito.GoToBegin();
+        itm.GoToBegin();
+
+        while (!ito.IsAtEnd()) {
+            if(itm.Get() == 1) {
+                ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
+            }
+            ++it;
+            ++ito;
+            ++itm;
+        }
+        //
+        //
+        // Write/Save results
+        this->template SetNextOutput<OutputImageType>(outputImage);
+    }
+    //--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif //#define clitkNormalizeImageFilterGenericFilter_txx