]> Creatis software - clitk.git/commitdiff
new tool to calculate the barycenter of a binary image
authorPresles Benoît <benoit.presles@creatis.insa-lyon.fr>
Tue, 16 Dec 2014 10:42:37 +0000 (11:42 +0100)
committerPresles Benoît <benoit.presles@creatis.insa-lyon.fr>
Tue, 16 Dec 2014 10:42:37 +0000 (11:42 +0100)
tools/CMakeLists.txt
tools/clitkImageBarycenter.cxx [new file with mode: 0644]
tools/clitkImageBarycenter.ggo [new file with mode: 0644]
tools/clitkImageBarycenterGenericFilter.h [new file with mode: 0644]
tools/clitkImageBarycenterGenericFilter.txx [new file with mode: 0644]

index 6bd72a3e62b55397fbaa4fb98de1aa2ce9e9a0a2..016b26a498425d551f82a255e34766e71db02342 100644 (file)
@@ -325,6 +325,11 @@ if(CLITK_BUILD_TOOLS)
   target_link_libraries(clitkBlurImage clitkCommon )
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBlurImage)
 
+  WRAP_GGO(clitkImageBarycenter_GGO_C clitkImageBarycenter.ggo)
+  add_executable(clitkImageBarycenter clitkImageBarycenter.cxx ${clitkImageBarycenter_GGO_C})
+  target_link_libraries(clitkImageBarycenter clitkCommon )
+  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBlurImage)
+
   #=========================================================
   option(CLITK_USE_ROOT "Build experimental tools using root" OFF)
   if (CLITK_USE_ROOT)
diff --git a/tools/clitkImageBarycenter.cxx b/tools/clitkImageBarycenter.cxx
new file mode 100644 (file)
index 0000000..03dea82
--- /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   clitkImageBarycenterGenericFilter.txx
+ * @author xxx <xxx@creatis.insa-lyon.fr>
+ * @date   29 June 2029
+ *
+ * @brief ImageBarycenter an image
+ *
+ ===================================================*/
+
+// clitk
+#include "clitkImageBarycenter_ggo.h"
+#include "clitkImageBarycenterGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkImageBarycenter, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::ImageBarycenterGenericFilter<args_info_clitkImageBarycenter> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+  filter->Update();
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitkImageBarycenter.ggo b/tools/clitkImageBarycenter.ggo
new file mode 100644 (file)
index 0000000..b366eb9
--- /dev/null
@@ -0,0 +1,12 @@
+#File clitkImageBarycenter.ggo
+package "clitkImageBarycenter"
+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
diff --git a/tools/clitkImageBarycenterGenericFilter.h b/tools/clitkImageBarycenterGenericFilter.h
new file mode 100644 (file)
index 0000000..695be52
--- /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 CLITKFooIMAGEGENERICFILTER_H
+#define CLITKFooIMAGEGENERICFILTER_H
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+template<class args_info_type>
+class ITK_EXPORT ImageBarycenterGenericFilter:
+        public ImageToImageGenericFilter<ImageBarycenterGenericFilter<args_info_type> >
+{
+
+public:
+
+    //--------------------------------------------------------------------
+    ImageBarycenterGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef ImageBarycenterGenericFilter         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(ImageBarycenterGenericFilter, 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 "clitkImageBarycenterGenericFilter.txx"
+#endif
+
+#endif // #define clitkImageBarycenterGenericFilter_h
diff --git a/tools/clitkImageBarycenterGenericFilter.txx b/tools/clitkImageBarycenterGenericFilter.txx
new file mode 100644 (file)
index 0000000..e4a6eaf
--- /dev/null
@@ -0,0 +1,175 @@
+/*=========================================================================
+  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 clitkImageBarycenterGenericFilter_txx
+#define clitkImageBarycenterGenericFilter_txx
+
+/* =================================================
+ * @file   clitkImageBarycenterGenericFilter.txx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ *
+ * @brief
+ *
+ ===================================================*/
+
+// itk include
+#include "itkConnectedComponentImageFilter.h"
+#include "itkLabelImageToShapeLabelMapFilter.h"
+#include <clitkCommon.h>
+
+namespace clitk
+{
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+ImageBarycenterGenericFilter<args_info_type>::ImageBarycenterGenericFilter():
+  ImageToImageGenericFilter<Self>("ImageBarycenter")
+{
+  InitializeImageType<2>();
+  InitializeImageType<3>();
+  //InitializeImageType<4>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<unsigned int Dim>
+void ImageBarycenterGenericFilter<args_info_type>::InitializeImageType()
+{
+  ADD_DEFAULT_IMAGE_TYPES(Dim);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+void ImageBarycenterGenericFilter<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);
+  }
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<class InputImageType>
+void
+ImageBarycenterGenericFilter<args_info_type>::UpdateWithInputImageType()
+{
+
+  // Reading input
+  typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+
+  // Main filter
+  typedef typename InputImageType::PixelType PixelType;
+  typedef itk::Image<unsigned char, InputImageType::ImageDimension> OutputImageType;
+
+  // Filter
+    typedef unsigned short                                LabelType;
+    typedef itk::ShapeLabelObject< LabelType, InputImageType::ImageDimension > ShapeLabelObjectType;
+    typedef itk::LabelMap< ShapeLabelObjectType >         LabelMapType;
+
+    typedef itk::ConnectedComponentImageFilter <InputImageType, OutputImageType > ConnectedComponentImageFilterType;
+    typedef itk::LabelImageToShapeLabelMapFilter< OutputImageType, LabelMapType> I2LType;
+    typename ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New ();
+    connected->SetInput(input);
+    connected->Update();
+    typedef itk::LabelImageToShapeLabelMapFilter< OutputImageType, LabelMapType> I2LType;
+    typename I2LType::Pointer i2l = I2LType::New();
+    i2l->SetInput( connected->GetOutput() );
+    i2l->SetComputePerimeter(true);
+    i2l->Update();
+    LabelMapType *labelMap = i2l->GetOutput();
+    std::cout << "The input image has " << labelMap->GetNumberOfLabelObjects() << " labels." << std::endl;
+    // Retrieve all attributes
+    //Only 1 object so:
+    unsigned int n = 0;
+    //for (unsigned int n = 0; n < labelMap->GetNumberOfLabelObjects(); ++n)
+    //{
+      ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(n);
+      std::cout << "Label: "
+                << typename itk::NumericTraits< typename LabelMapType::LabelType >::PrintType(labelObject->GetLabel()) << std::endl;
+      //std::cout << "    BoundingBox: "
+      //          << labelObject->GetBoundingBox() << std::endl;
+      //std::cout << "    NumberOfPixels: "
+      //          << labelObject->GetNumberOfPixels() << std::endl;
+      //std::cout << "    PhysicalSize: "
+      //          << labelObject->GetPhysicalSize() << std::endl;
+      std::cout << "    Centroid: "
+                << labelObject->GetCentroid() << std::endl;
+      //std::cout << "    NumberOfPixelsOnBorder: "
+      //          << labelObject->GetNumberOfPixelsOnBorder() << std::endl;
+      //std::cout << "    PerimeterOnBorder: "
+      //          << labelObject->GetPerimeterOnBorder() << std::endl;
+      //std::cout << "    FeretDiameter: "
+      //          << labelObject->GetFeretDiameter() << std::endl;
+      //std::cout << "    PrincipalMoments: "
+      //          << labelObject->GetPrincipalMoments() << std::endl;
+      //std::cout << "    PrincipalAxes: "
+      //          << labelObject->GetPrincipalAxes() << std::endl;
+      //std::cout << "    Elongation: "
+      //          << labelObject->GetElongation() << std::endl;
+      //std::cout << "    Perimeter: "
+      //          << labelObject->GetPerimeter() << std::endl;
+      //std::cout << "    Roundness: "
+      //          << labelObject->GetRoundness() << std::endl;
+      //std::cout << "    EquivalentSphericalRadius: "
+      //          << labelObject->GetEquivalentSphericalRadius() << std::endl;
+      //std::cout << "    EquivalentSphericalPerimeter: "
+      //          << labelObject->GetEquivalentSphericalPerimeter() << std::endl;
+      //std::cout << "    EquivalentEllipsoidDiameter: "
+      //          << labelObject->GetEquivalentEllipsoidDiameter() << std::endl;
+      //std::cout << "    Flatness: "
+      //          << labelObject->GetFlatness() << std::endl;
+      //std::cout << "    PerimeterOnBorderRatio: "
+      //          << labelObject->GetPerimeterOnBorderRatio() << std::endl;
+      //}
+
+    typename OutputImageType::Pointer outputImage = OutputImageType::New();
+    typename OutputImageType::RegionType region_outputImage(input->GetLargestPossibleRegion());
+    outputImage->SetRegions(region_outputImage);
+    outputImage->SetOrigin(input->GetOrigin());
+    outputImage->SetSpacing(input->GetSpacing());
+    outputImage->SetDirection(input->GetDirection());
+    outputImage->Allocate();
+    outputImage->FillBuffer(0);
+
+    typename InputImageType::IndexType barycenterIndex;
+    input->TransformPhysicalPointToIndex(labelObject->GetCentroid(),barycenterIndex);
+
+    outputImage->SetPixel(barycenterIndex,1);
+    // Write/Save results
+    this->template SetNextOutput<OutputImageType>(outputImage);
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif //#define clitkImageBarycenterGenericFilter_txx