]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 10 Dec 2013 12:20:48 +0000 (13:20 +0100)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 10 Dec 2013 12:20:48 +0000 (13:20 +0100)
common/clitkIO.cxx
common/clitkImageCommon.cxx
tools/CMakeLists.txt
tools/clitkImageIntensityWindowing.cxx [new file with mode: 0644]
tools/clitkImageIntensityWindowing.ggo [new file with mode: 0644]
tools/clitkImageIntensityWindowingGenericFilter.h [new file with mode: 0644]
tools/clitkImageIntensityWindowingGenericFilter.txx [new file with mode: 0644]

index 5c5977baa4fb7326da551a662a1ab44c1cf35459..aa42db89ea2998a3df138f18a8cc5e1de565d2d3 100644 (file)
@@ -45,6 +45,7 @@
 #endif
 #if ITK_VERSION_MAJOR >= 4
   #include "itkGDCMImageIOFactory.h"
+  #include "itkPNGImageIOFactory.h"
 #endif
 
 //--------------------------------------------------------------------
@@ -59,6 +60,14 @@ void clitk::RegisterClitkFactories()
       itk::GDCMImageIOFactory::UnRegisterFactory(*it);
       break;
     }
+
+  std::list< itk::ObjectFactoryBase * > flpng = itk::PNGImageIOFactory::GetRegisteredFactories();
+  for (std::list< itk::ObjectFactoryBase * >::iterator it = flpng.begin(); it != flpng.end(); ++it)
+    if (dynamic_cast<itk::PNGImageIOFactory *>(*it))
+    {
+      itk::PNGImageIOFactory::UnRegisterFactory(*it);
+      break;
+    }
 #endif
 #if CLITK_PRIVATE_FEATURES
   clitk::UsfImageIOFactory::RegisterOneFactory();
@@ -81,6 +90,7 @@ void clitk::RegisterClitkFactories()
   clitk::EsrfHstImageIOFactory::RegisterOneFactory();
 #if ITK_VERSION_MAJOR >= 4
   itk::GDCMImageIOFactory::RegisterOneFactory();
+  itk::PNGImageIOFactory::RegisterOneFactory();
 #endif
 } ////
 
index 40298452e5430218a3952fbf30a88398d17dc5f3..83b9435854ef3f7bec71e764ccee787ba314e0f9 100644 (file)
@@ -101,11 +101,11 @@ void clitk::printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os
     for(unsigned int i=0; i< dim-1; i++)
       os << inputSize[i] << "x";
     os << inputSize[dim-1]
-       << "  ";
+       << " ";
     for(unsigned int i=0; i< dim-1; i++)
       os << inputSpacing[i] << "x";
     os << inputSpacing[dim-1]
-       << "  ";
+       << " ";
     for(unsigned int i=0; i< dim-1; i++)
       os << inputOrigin[i] << "x";
     os << inputOrigin[dim-1] << " ";
index e6cdd02e697f6fc62e335fec84fbdce3d51ac4c5..478b8173b76f8d8ac1fcfdd7353caade239b11e4 100644 (file)
@@ -310,6 +310,11 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkImageLaplacian clitkCommon )
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageLaplacian)
 
+  WRAP_GGO(clitkImageIntensityWindowing_GGO_C clitkImageIntensityWindowing.ggo)
+  ADD_EXECUTABLE(clitkImageIntensityWindowing clitkImageIntensityWindowing.cxx ${clitkImageIntensityWindowing_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkImageIntensityWindowing clitkCommon )
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageIntensityWindowing)
+
 
   #=========================================================
   option(CLITK_USE_ROOT "Build experimental tools using root" OFF)
diff --git a/tools/clitkImageIntensityWindowing.cxx b/tools/clitkImageIntensityWindowing.cxx
new file mode 100644 (file)
index 0000000..e7e01fa
--- /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   clitkImageIntensityWindowingGenericFilter.txx
+ * @author xxx <xxx@creatis.insa-lyon.fr>
+ * @date   29 June 2029
+ *
+ * @brief ImageIntensityWindowing an image
+ *
+ ===================================================*/
+
+// clitk
+#include "clitkImageIntensityWindowing_ggo.h"
+#include "clitkImageIntensityWindowingGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkImageIntensityWindowing, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::ImageIntensityWindowingGenericFilter<args_info_clitkImageIntensityWindowing> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+  filter->Update();
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitkImageIntensityWindowing.ggo b/tools/clitkImageIntensityWindowing.ggo
new file mode 100644 (file)
index 0000000..6b7fe46
--- /dev/null
@@ -0,0 +1,13 @@
+#File clitkImageIntensityWindowing.ggo
+package "clitkImageIntensityWindowing"
+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/clitkImageIntensityWindowingGenericFilter.h b/tools/clitkImageIntensityWindowingGenericFilter.h
new file mode 100644 (file)
index 0000000..41f88e1
--- /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 CLITKImageIntensityWindowingGENERICFILTER_H
+#define CLITKImageIntensityWindowingGENERICFILTER_H
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+template<class args_info_type>
+class ITK_EXPORT ImageIntensityWindowingGenericFilter:
+        public ImageToImageGenericFilter<ImageIntensityWindowingGenericFilter<args_info_type> >
+{
+
+public:
+
+    //--------------------------------------------------------------------
+    ImageIntensityWindowingGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef ImageIntensityWindowingGenericFilter         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(ImageIntensityWindowingGenericFilter, 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 "clitkImageIntensityWindowingGenericFilter.txx"
+#endif
+
+#endif // #define clitkImageIntensityWindowingGenericFilter_h
diff --git a/tools/clitkImageIntensityWindowingGenericFilter.txx b/tools/clitkImageIntensityWindowingGenericFilter.txx
new file mode 100644 (file)
index 0000000..02f4acd
--- /dev/null
@@ -0,0 +1,167 @@
+/*=========================================================================
+  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 clitkImageIntensityWindowingGenericFilter_txx
+#define clitkImageIntensityWindowingGenericFilter_txx
+
+/* =================================================
+ * @file   clitkImageIntensityWindowingGenericFilter.txx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ *
+ * @brief
+ *
+ ===================================================*/
+
+// itk include
+#include "itkIntensityWindowingImageFilter.h"
+#include "itkLabelStatisticsImageFilter.h"
+#include "itkMaskImageFilter.h"
+#include "itkMaskNegatedImageFilter.h"
+#include <clitkCommon.h>
+
+namespace clitk
+{
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+ImageIntensityWindowingGenericFilter<args_info_type>::ImageIntensityWindowingGenericFilter():
+  ImageToImageGenericFilter<Self>("ImageIntensityWindowing")
+{
+  InitializeImageType<2>();
+  InitializeImageType<3>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<unsigned int Dim>
+void ImageIntensityWindowingGenericFilter<args_info_type>::InitializeImageType()
+{
+  ADD_DEFAULT_IMAGE_TYPES(Dim);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+void ImageIntensityWindowingGenericFilter<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
+ImageIntensityWindowingGenericFilter<args_info_type>::UpdateWithInputImageType()
+{
+
+  // Main filter
+  typedef typename InputImageType::PixelType InputPixelType;
+  typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
+  typedef itk::Image<unsigned char, InputImageType::ImageDimension> MaskImageType;
+
+  // Reading input
+  typename OutputImageType::Pointer input = this->template GetInput<OutputImageType>(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);
+  }
+  // Set mask iterator
+  typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
+  IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
+  //
+  typedef itk::LabelStatisticsImageFilter< OutputImageType, MaskImageType > LabelStatisticsImageFilterType;
+  typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
+  labelStatisticsImageFilter->SetLabelInput( mask );
+  labelStatisticsImageFilter->SetInput(input);
+  labelStatisticsImageFilter->Update();
+  float maxImg = labelStatisticsImageFilter->GetMaximum(1);
+  //std::cout << "maxImg: " << maxImg << std::endl;
+  // Filter
+  typedef itk::IntensityWindowingImageFilter <OutputImageType, OutputImageType> IntensityWindowingImageFilterType;
+  typename IntensityWindowingImageFilterType::Pointer filter = IntensityWindowingImageFilterType::New();
+  filter->SetInput(input);
+  filter->SetWindowMinimum(0.0);
+  filter->SetWindowMaximum(maxImg);
+  filter->SetOutputMinimum(0.0);
+  filter->SetOutputMaximum(1.0);
+  filter->Update();
+
+  // Set iterator
+  typedef itk::ImageRegionIterator<OutputImageType> IteratorType;
+  IteratorType it(filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
+  //A little bit strange to do that but I think I need to do it.
+  // Create output image
+  typename OutputImageType::Pointer outputImage = OutputImageType::New();
+  outputImage->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
+  outputImage->SetOrigin(filter->GetOutput()->GetOrigin());
+  outputImage->SetSpacing(filter->GetOutput()->GetSpacing());
+  outputImage->Allocate();
+  outputImage->FillBuffer(-100.0);
+  // Set output iterator
+  typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
+  IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
+
+  it.GoToBegin();
+  ito.GoToBegin();
+  itm.GoToBegin();
+
+  while (!ito.IsAtEnd()) {
+      if(itm.Get() > 0) {
+          ito.Set(it.Get());
+      }
+      ++it;
+      ++ito;
+      ++itm;
+  }
+
+  // Write/Save results
+  this->template SetNextOutput<OutputImageType>(outputImage);
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif //#define clitkImageIntensityWindowingGenericFilter_txx