TuttleOFX
1
|
00001 #ifndef _TERRY_SAMPLER_GAUSSIAN_HPP_ 00002 #define _TERRY_SAMPLER_GAUSSIAN_HPP_ 00003 00004 #include "details.hpp" 00005 #include <boost/math/constants/constants.hpp> 00006 00007 namespace terry { 00008 using namespace boost::gil; 00009 namespace sampler { 00010 00011 // from http://avisynth.org/mediawiki/Resampling#Gaussian_resampler 00012 00013 00014 struct gaussian_sampler 00015 { 00016 const size_t _windowSize; 00017 RESAMPLING_CORE_TYPE _sigma; 00018 00019 gaussian_sampler() : 00020 _windowSize ( 4.0 ), // size = 3.0 00021 _sigma ( 1.0 ) 00022 { 00023 } 00024 00025 gaussian_sampler( size_t windowSize, size_t sigma ) : 00026 _windowSize ( windowSize + 1 ), 00027 _sigma ( sigma ) 00028 { 00029 } 00030 00031 template< typename Weight > 00032 void operator()( const RESAMPLING_CORE_TYPE& distance, Weight& weight ) 00033 { 00034 if( _sigma > -std::numeric_limits<RESAMPLING_CORE_TYPE>::epsilon() && 00035 _sigma < std::numeric_limits<RESAMPLING_CORE_TYPE>::epsilon()) 00036 { 00037 weight = 0.0; 00038 return; 00039 } 00040 //weight = std::pow( 2.f, - 0.1 * _sigma * distance * distance ); 00041 weight = 1.0 / ( _sigma * std::sqrt( 2 * boost::math::constants::pi<RESAMPLING_CORE_TYPE>() )) * std::exp( - distance * distance / ( 2 * _sigma ) ) ; 00042 } 00043 }; 00044 00045 } 00046 } 00047 00048 #endif 00049