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 #include "cmtkTypedArrayNoiseEstimatorNaiveGaussian.h"
00032
00033 namespace
00034 cmtk
00035 {
00036
00037 TypedArrayNoiseEstimatorNaiveGaussian::TypedArrayNoiseEstimatorNaiveGaussian
00038 ( const TypedArray* data, const size_t histogramBins )
00039 {
00040 Histogram<unsigned int>::SmartPtr histogram( data->GetHistogram( histogramBins ) );
00041
00042
00043 size_t idx = 0;
00044 while ( (idx < (histogramBins-1)) && ( (*histogram)[idx] <= (*histogram)[idx+1] ) )
00045 {
00046 ++idx;
00047 }
00048
00049 const Types::DataItem noiseMean = histogram->BinToValue( idx );
00050
00051
00052 while ( (idx < (histogramBins-1)) && ( (*histogram)[idx] > (*histogram)[idx+1] ) )
00053 {
00054 ++idx;
00055 }
00056
00057
00058
00059 const Types::DataItem threshold = histogram->BinToValue( idx );
00060
00061 Types::DataItem sdev = 0;
00062 size_t count = 0;
00063 for ( size_t i = 0; i < data->GetDataSize(); ++i )
00064 {
00065 Types::DataItem value;
00066 if ( data->Get( value, i ) )
00067 {
00068 if ( value <= threshold )
00069 {
00070 sdev += static_cast<Types::DataItem>( MathUtil::Square( value - noiseMean ) );
00071 ++count;
00072 }
00073 }
00074 }
00075
00076 if ( count )
00077 this->m_NoiseLevelSigma = static_cast<Types::DataItem>( sqrt( sdev/count ) );
00078 else
00079 this->m_NoiseLevelSigma = 0.0;
00080 }
00081
00082 }