TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_NLMDENOISERPROCESS_HPP_ 00002 #define _TUTTLE_PLUGIN_NLMDENOISERPROCESS_HPP_ 00003 00004 #include "NLMDenoiserPlugin.hpp" 00005 00006 #include <tuttle/common/utils/global.hpp> 00007 #include <tuttle/plugin/ImageGilProcessor.hpp> 00008 #include <tuttle/plugin/exceptions.hpp> 00009 #include <terry/globals.hpp> 00010 00011 #include <cmath> 00012 #include <vector> 00013 #include <ofxsImageEffect.h> 00014 #include <ofxsMultiThread.h> 00015 00016 #include <boost/gil/gil_all.hpp> 00017 00018 #include <boost/ptr_container/ptr_vector.hpp> 00019 #include <boost/array.hpp> 00020 #include <boost/scoped_ptr.hpp> 00021 #include <boost/scoped_array.hpp> 00022 00023 namespace tuttle { 00024 namespace plugin { 00025 namespace nlmDenoiser { 00026 00027 struct NlmParams 00028 { 00029 boost::array<float,4> mix; 00030 boost::array<float,4> bws; 00031 int patchRadius; 00032 int regionRadius; 00033 double preBlurring; 00034 }; 00035 00036 /** 00037 * @brief Base class for the denoising processor 00038 */ 00039 template<class View> 00040 class NLMDenoiserProcess 00041 : public ImageGilProcessor<View> 00042 { 00043 public: 00044 typedef typename View::value_type Pixel; 00045 typedef typename boost::gil::channel_type<View>::type Channel; 00046 00047 protected: 00048 OFX::BooleanParam* _paramOptimized; ///< Perform optimization (quality++, speed+++) 00049 OFX::DoubleParam* _paramPreBlurring; ///< Perform pre blurring 00050 OFX::IntParam* _paramPatchRadius; ///< Patch size for nl-means algorithm 00051 OFX::IntParam* _paramRegionRadius; ///< Region radius size 00052 OFX::IntParam* _paramDepth; ///< depth for nl-means algorithm 00053 OFX::DoubleParam* _paramRedStrength; ///< Red color effect mix 00054 OFX::DoubleParam* _paramGreenStrength; ///< Green color effect mix 00055 OFX::DoubleParam* _paramBlueStrength; ///< Blue color effect mix 00056 OFX::DoubleParam* _paramRedGrainSize; ///< Red color effect bandwidth 00057 OFX::DoubleParam* _paramGreenGrainSize; ///< Green color effect bandwidth 00058 OFX::DoubleParam* _paramBlueGrainSize; ///< Blue color effect bandwidth 00059 00060 std::vector< View > _srcViews; ///< Array of source image view (3D-NLMeans) 00061 boost::ptr_vector< OFX::Image > _srcImgs; 00062 00063 NLMDenoiserPlugin & _plugin; ///< Rendering plugin 00064 00065 int _margin; ///< Margin 00066 OfxRectI _upScaledBounds; ///< Upscaled source bounds (margin upscaling) 00067 00068 protected: 00069 void addFrame( const OfxRectI & dBounds, const int dstBitDepth, 00070 const int dstComponents, const double time, const int z ); 00071 00072 public: 00073 NLMDenoiserProcess( NLMDenoiserPlugin & instance ); 00074 ~NLMDenoiserProcess( ); 00075 00076 void setup( const OFX::RenderArguments &args ); 00077 void preProcess( ); 00078 void multiThreadProcessImages( const OfxRectI& procWindowRoW ); 00079 00080 double computeBandwidth( ); 00081 void nlMeans( View& dst, const OfxRectI& procWindow, const NlmParams& params ); 00082 00083 void computeWeights( const std::vector< View > & srcViews, 00084 const OfxRectI & procWindow, 00085 boost::gil::rgba32f_view_t & view_wc, 00086 boost::gil::rgba32f_view_t & view_norm, 00087 const NlmParams & params ); 00088 }; 00089 00090 } 00091 } 00092 } 00093 00094 #include "NLMDenoiserProcess.tcc" 00095 00096 #endif 00097