Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkVoxelMatchingCorrRatio_h_included_
00034 #define __cmtkVoxelMatchingCorrRatio_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Registration/cmtkRegistrationJointHistogram.h>
00039 #include <Base/cmtkInterpolator.h>
00040 #include <System/cmtkSmartPtr.h>
00041
00042 namespace
00043 cmtk
00044 {
00045
00048
00052 template< Interpolators::InterpolationEnum I = Interpolators::LINEAR >
00053 class VoxelMatchingCorrRatio :
00054 public VoxelMatchingMetric<short,TYPE_SHORT,I>
00055 {
00056 public:
00058 typedef VoxelMatchingCorrRatio<I> Self;
00059
00061 typedef SmartPointer<Self> SmartPtr;
00062
00068 VoxelMatchingCorrRatio ( const UniformVolume* refVolume, const UniformVolume* fltVolume, const unsigned int numBins = CMTK_HISTOGRAM_AUTOBINS )
00069 : VoxelMatchingMetric<short,TYPE_SHORT,I>( refVolume, fltVolume )
00070 {
00071 NumBinsX = NumBinsY = numBins;
00072
00073 if ( NumBinsX == CMTK_HISTOGRAM_AUTOBINS )
00074 NumBinsX = std::max<unsigned>( std::min<unsigned>( refVolume->GetNumberOfPixels(), 128 ), 8 );
00075 HistogramI.Resize( NumBinsX );
00076
00077 if ( NumBinsY == CMTK_HISTOGRAM_AUTOBINS )
00078 NumBinsY = std::max<unsigned>( std::min<unsigned>( fltVolume->GetNumberOfPixels(), 128 ), 8 );
00079 HistogramJ.Resize( NumBinsY );
00080
00081 HistogramI.SetRange( refVolume->GetData()->GetRange() );
00082
00083 SumJ.resize( NumBinsX );
00084 SumJ2.resize( NumBinsX );
00085
00086 fltVolume->GetData()->GetStatistics( MuJ, SigmaSqJ );
00087
00088 HistogramJ.SetRange( fltVolume->GetData()->GetRange() );
00089
00090 SumI.resize( NumBinsY );
00091 SumI2.resize( NumBinsY );
00092
00093 refVolume->GetData()->GetStatistics( MuI, SigmaSqI );
00094 }
00095
00100 void Reset()
00101 {
00102 HistogramI.Reset();
00103 HistogramJ.Reset();
00104 std::fill( SumI.begin(), SumI.end(), 0 );
00105 std::fill( SumJ.begin(), SumJ.end(), 0 );
00106 std::fill( SumI2.begin(), SumI2.end(), 0 );
00107 std::fill( SumJ2.begin(), SumJ2.end(), 0 );
00108 }
00109
00114 template<class T> void Increment( const T a, const T b )
00115 {
00116
00117 size_t bin = HistogramI.ValueToBin( a );
00118
00119 HistogramI.Increment( bin );
00120
00121 SumJ[bin] += b;
00122
00123 SumJ2[bin] += b * b;
00124
00125
00126 bin = HistogramJ.ValueToBin( b );
00127 HistogramJ.Increment( bin );
00128 SumI[bin] += a;
00129 SumI2[bin] += a * a;
00130 }
00131
00134 template<class T> void Decrement( const T a, const T b )
00135 {
00136
00137 size_t bin = HistogramI.ValueToBin( a );
00138
00139 HistogramI.Decrement( bin );
00140
00141 SumJ[bin] -= b;
00142
00143 SumJ2[bin] -= b * b;
00144
00145
00146 bin = HistogramJ.ValueToBin( b );
00147 HistogramJ.Decrement( bin );
00148 SumI[bin] -= a;
00149 SumI2[bin] -= a * a;
00150 }
00151
00154 void AddMetric ( const Self& other )
00155 {
00156 HistogramI.AddHistogram( other.HistogramI );
00157 for ( size_t bin = 0; bin < NumBinsX; ++bin )
00158 {
00159 SumJ[bin] += other.SumJ[bin];
00160 SumJ2[bin] += other.SumJ2[bin];
00161 }
00162
00163 HistogramJ.AddHistogram( other.HistogramJ );
00164 for ( size_t bin = 0; bin < NumBinsY; ++bin )
00165 {
00166 SumI[bin] += other.SumI[bin];
00167 SumI2[bin] += other.SumI2[bin];
00168 }
00169 }
00170
00173 void RemoveMetric ( const Self& other )
00174 {
00175 HistogramI.RemoveHistogram( other.HistogramI );
00176 for ( size_t bin = 0; bin < NumBinsX; ++bin ) {
00177 SumJ[bin] -= other.SumJ[bin];
00178 SumJ2[bin] -= other.SumJ2[bin];
00179 }
00180
00181 HistogramJ.RemoveHistogram( other.HistogramJ );
00182 for ( size_t bin = 0; bin < NumBinsY; ++bin ) {
00183 SumI[bin] -= other.SumI[bin];
00184 SumI2[bin] -= other.SumI2[bin];
00185 }
00186 }
00187
00189 typename Self::ReturnType Get () const;
00190
00191 private:
00193 size_t NumBinsX;
00194
00196 std::vector<double> SumJ;
00197
00199 std::vector<double> SumJ2;
00200
00202 Histogram<unsigned int> HistogramI;
00203
00204
00205 Types::DataItem SigmaSqJ;
00206
00207
00208 Types::DataItem MuJ;
00209
00211 size_t NumBinsY;
00212
00214 std::vector<double> SumI;
00215
00217 std::vector<double> SumI2;
00218
00220 Histogram<unsigned int> HistogramJ;
00221
00222
00223 Types::DataItem SigmaSqI;
00224
00225
00226 Types::DataItem MuI;
00227 };
00228
00230 typedef VoxelMatchingCorrRatio<Interpolators::LINEAR> VoxelMatchingCorrRatio_Trilinear;
00231
00233 typedef VoxelMatchingCorrRatio<Interpolators::NEAREST_NEIGHBOR> VoxelMatchingCorrRatio_NearestNeighbor;
00234
00236
00237 }
00238
00239 #endif // #ifndef __cmtkVoxelMatchingCorrRatio_h_included_