]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkImageStatistics.h
Issue #1959 - New black box to calculate the minimum, maximum, std
[bbtk.git] / packages / itk / src / bbitkImageStatistics.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbitkImageStatistics.h,v $
31   Language:  C++
32   Date:      $Date: 2013/03/27 $
33   Version:   $Revision: 1.0 $
34   Modified by: Ricardo A Corredor (RaC)
35 =========================================================================*/
36
37
38 /**
39  * \file
40  * \brief class ITKImageStatistics : generic ITKImage statistics
41  */
42 /**
43  * \class bbtk::ITKImageStatistics
44  * \brief Generic ITKImage statictis
45  */
46
47 #ifdef _USE_ITK_
48 //===== 
49 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
50 //===== 
51 #ifndef __bbitkImageStatistics_h_INCLUDED__
52 #define __bbitkImageStatistics_h_INCLUDED__
53 //#include "bbitk_EXPORT.h"
54 #include "bbtkAtomicBlackBox.h"
55
56 #include "iostream"
57
58 #include "bbitkImage.h"
59
60 #include <itkStatisticsImageFilter.h>
61
62
63 namespace bbitk
64 {
65
66 class /*bbitk_EXPORT*/ ImageStatistics
67  : 
68    public bbtk::AtomicBlackBox
69 {
70   BBTK_BLACK_BOX_INTERFACE(ImageStatistics,bbtk::AtomicBlackBox);
71 //===== 
72 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
73 //===== 
74   BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
75   BBTK_DECLARE_OUTPUT(Min,double);
76   BBTK_DECLARE_OUTPUT(Max,double);
77   BBTK_DECLARE_OUTPUT(Mean,double);
78   BBTK_DECLARE_OUTPUT(StdDev,double);
79   BBTK_PROCESS(Process);
80 private:
81   inline void Process();
82   template <class T> void ProcessTemplated();
83 //===== 
84 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
85 //===== 
86 };
87
88 BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageStatistics,bbtk::AtomicBlackBox);
89 BBTK_NAME("ImageStatistics");
90 BBTK_AUTHOR("Ricardo A Corredor");
91 BBTK_DESCRIPTION("Basic Image Statistics (minimim, maximum, mean, standard deviation)");
92 BBTK_CATEGORY("");
93 BBTK_INPUT(ImageStatistics,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
94 BBTK_OUTPUT(ImageStatistics,Min,"Image minimum",double,"");
95 BBTK_OUTPUT(ImageStatistics,Max,"Image maximum",double,"");
96 BBTK_OUTPUT(ImageStatistics,Mean,"Image mean",double,"");
97 BBTK_OUTPUT(ImageStatistics,StdDev,"Image standard deviation",double,"");
98 BBTK_END_DESCRIBE_BLACK_BOX(ImageStatistics);
99 //===== 
100 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
101 //===== 
102
103
104 //===================================================
105 void ImageStatistics::Process()
106 {
107         bbtk::TypeInfo t = bbGetInputIn().type();
108         BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
109 }
110 //===================================================
111
112
113 //===================================================
114 template <class ImageType>
115 void ImageStatistics::ProcessTemplated()
116 {
117         bbtkDebugMessageInc("Core",9,"bbitk::ImageStatistics::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
118
119         typedef itk::StatisticsImageFilter<ImageType> StatisticsImageFilterType;
120         typename StatisticsImageFilterType::Pointer statisticsImageFilter = StatisticsImageFilterType::New ();
121
122         // Input
123         ImageType* in = this->bbGetInputIn().get<ImageType*>();
124
125         statisticsImageFilter->SetInput(in);
126         statisticsImageFilter->Update();
127
128         std::cout << "Mean: " << statisticsImageFilter->GetMean() << std::endl;
129         std::cout << "Std.: " << statisticsImageFilter->GetSigma() << std::endl;
130         std::cout << "Min: " << statisticsImageFilter->GetMinimum() << std::endl;
131         std::cout << "Max: " << statisticsImageFilter->GetMaximum() << std::endl;
132
133         bbSetOutputMin((double)statisticsImageFilter->GetMinimum());
134         bbSetOutputMax((double)statisticsImageFilter->GetMaximum());
135         bbSetOutputMean((double)statisticsImageFilter->GetMean());
136         bbSetOutputStdDev((double)statisticsImageFilter->GetSigma());
137
138         bbtkDebugDecTab("Core",9);
139 }
140 //===================================================
141
142 }
143 // EO namespace bbitk
144
145 #endif // __bbitkImageStatistics_h_INCLUDED__
146
147 #endif  // _USE_ITK_