cmtkImagePairSimilarityMeasureCR.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkImagePairSimilarityMeasureCR_h_included_
00034 #define __cmtkImagePairSimilarityMeasureCR_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Registration/cmtkImagePairSimilarityMeasure.h>
00039 #include <System/cmtkSmartPtr.h>
00040 
00041 #include <vector>
00042 
00043 namespace
00044 cmtk
00045 {
00046 
00049 
00052 class ImagePairSimilarityMeasureCR : 
00054   public ImagePairSimilarityMeasure
00055 {
00056 public:
00058   typedef ImagePairSimilarityMeasureCR Self;
00059 
00061   typedef SmartPointer<Self> SmartPtr;
00062 
00068   ImagePairSimilarityMeasureCR ( const UniformVolume::SmartPtr& refVolume, const UniformVolume::SmartPtr& fltVolume,
00069                                  const Interpolators::InterpolationEnum interpolation = Interpolators::DEFAULT );
00070 
00072   virtual ~ImagePairSimilarityMeasureCR() {}
00073   
00078   virtual void Reset() 
00079   {
00080     HistogramI.Reset();
00081     HistogramJ.Reset();
00082     std::fill( SumI.begin(), SumI.end(), 0 );
00083     std::fill( SumJ.begin(), SumJ.end(), 0 );
00084     std::fill( SumI2.begin(), SumI2.end(), 0 );
00085     std::fill( SumJ2.begin(), SumJ2.end(), 0 );
00086   }
00087 
00092   template<class T> void Increment( const T a, const T b )
00093   {
00094     // what's the reference histogram bin?
00095     size_t bin = HistogramI.ValueToBin( a );
00096     // count this sample
00097     HistogramI.Increment( bin );
00098     // add floating value to sum of values for this class
00099     SumJ[bin] += b;
00100     // add squared floating value to sum of squared values for this class
00101     SumJ2[bin] += b * b;
00102 
00103     // same in reverse
00104     bin = HistogramJ.ValueToBin( b );
00105     HistogramJ.Increment( bin );
00106     SumI[bin] += a;
00107     SumI2[bin] += a * a;
00108   }
00109 
00112   template<class T> void Decrement( const T a, const T b )
00113   {
00114     // what's the reference histogram bin?
00115     size_t bin = HistogramI.ValueToBin( a );
00116     // count this sample
00117     HistogramI.Decrement( bin );
00118     // add floating value to sum of values for this class
00119     SumJ[bin] -= b;
00120     // add squared floating value to sum of squared values for this class
00121     SumJ2[bin] -= b * b;
00122 
00123     // same in reverse
00124     bin = HistogramJ.ValueToBin( b );
00125     HistogramJ.Decrement( bin );
00126     SumI[bin] -= a;
00127     SumI2[bin] -= a * a;
00128   }
00129 
00132   void Add ( const Self& other )
00133   {
00134     HistogramI.AddHistogram( other.HistogramI );
00135     for ( size_t bin = 0; bin < NumBinsX; ++bin ) 
00136       {
00137       SumJ[bin] += other.SumJ[bin];
00138       SumJ2[bin] += other.SumJ2[bin];
00139       }
00140     
00141     HistogramJ.AddHistogram( other.HistogramJ );
00142     for ( size_t bin = 0; bin < NumBinsY; ++bin ) 
00143       {
00144       SumI[bin] += other.SumI[bin];
00145       SumI2[bin] += other.SumI2[bin];
00146       }
00147   }
00148   
00151   void Remove ( const Self& other )
00152   {
00153     HistogramI.RemoveHistogram( other.HistogramI );
00154     for ( size_t bin = 0; bin < NumBinsX; ++bin )
00155       {
00156       SumJ[bin] -= other.SumJ[bin];
00157       SumJ2[bin] -= other.SumJ2[bin];
00158       }
00159     
00160     HistogramJ.RemoveHistogram( other.HistogramJ );
00161     for ( size_t bin = 0; bin < NumBinsY; ++bin ) 
00162       {
00163       SumI[bin] -= other.SumI[bin];
00164       SumI2[bin] -= other.SumI2[bin];
00165       }
00166   }
00167 
00169   virtual Self::ReturnType Get () const;
00170 
00171 private:
00173   size_t NumBinsX;
00174   
00176   std::vector<double> SumJ;
00177 
00179   std::vector<double> SumJ2;
00180 
00182   Histogram<unsigned int> HistogramI;
00183 
00184   // Variance of complete floating image for normalization.
00185   Types::DataItem SigmaSqJ;
00186 
00187   // Mean of complete floating image for normalization.
00188   Types::DataItem MuJ;
00189 
00191   size_t NumBinsY;
00192   
00194   std::vector<double> SumI;
00195 
00197   std::vector<double> SumI2;
00198 
00200   Histogram<unsigned int> HistogramJ;
00201 
00202   // Variance of complete floating image for normalization.
00203   Types::DataItem SigmaSqI;
00204 
00205   // Mean of complete floating image for normalization.
00206   Types::DataItem MuI;
00207 };
00208 
00210 
00211 } // namespace cmtk
00212 
00213 #endif // #ifndef __cmtkImagePairSimilarityMeasureCR_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines