00001 #ifndef Impala_Visualization_Background_h
00002 #define Impala_Visualization_Background_h
00003
00004 #include "Core/Array/RGB2Intensity.h"
00005 #include "Core/Array/MulVal.h"
00006 #include "Core/Array/MaximumVal.h"
00007 #include "Core/Array/Dilation.h"
00008 #include "Core/Array/GreaterThan.h"
00009 #include "Core/Array/RecGauss.h"
00010 #include "Core/Array/ColorSpace.h"
00011 #include "Core/Array/Rgb2Ooo.h"
00012 #include "Core/Array/ProjectRange.h"
00013 #include "Core/Matrix/MatSet.h"
00014 #include "Core/VideoSet/VxsDocument.h"
00015 #include "Core/Database/DataDocumentListener.h"
00016 #include "Visualization/Window.h"
00017 #include "Core/Array/Statistics.h"
00018
00019 namespace Impala
00020 {
00021 namespace Visualization
00022 {
00023
00024
00025 class Background : public Core::Database::DataDocumentListener
00026 {
00027 public:
00028 typedef Core::Array::Array2dScalarReal64 Array2dScalarReal64;
00029 typedef Core::Array::Array2dVec3Real64 Array2dVec3Real64;
00030 typedef Core::Array::Array2dScalarUInt8 Array2dScalarUInt8;
00031 typedef Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00032
00033
00034 Background(Core::Database::DataDocument* dataDoc, Window* wnd,
00035 double viewScale)
00036 {
00037 mDataDoc = dataDoc;
00038 mViewScale = viewScale;
00039 mWnd = wnd;
00040
00041 mStat = new Core::Array::Statistics<Array2dScalarReal64>(25, false);
00042
00043 mSigma = 3.0;
00044 Array2dScalarReal64* g = 0;
00045 g = Core::Array::MakeGaussIIR1d(mSigma, 0, 3.0);
00046 mBorderSize = g->CW();
00047 delete g;
00048
00049 Reset();
00050 }
00051
00052 virtual void
00053 HandleNewFile()
00054 {
00055 HandleNewFrame();
00056 }
00057
00058 virtual void
00059 HandleNewFrame()
00060 {
00061 int view = 0;
00062
00063 Core::Array::ArraySystem& aSys = Core::Array::ArraySystem::Instance();
00064 aSys.MarkMemoryUsage(false);
00065
00066 Core::Array::Array2dVec3UInt8* srcWrap = mDataDoc->VisualAtCursor(false);
00067 if (!srcWrap)
00068 return;
00069 Array2dVec3Real64* srcV3R64 = Core::Array::ArrayCreate<Array2dVec3Real64>
00070 (srcWrap->CW(), srcWrap->CH(), mBorderSize, mBorderSize);
00071
00072 Array2dScalarReal64* lum = 0;
00073 Array2dScalarReal64* col = 0;
00074 Array2dScalarReal64* tmp = 0;
00075
00076 Core::Array::Rgb2Ooo(srcV3R64, srcWrap);
00077
00078 Core::Array::ProjectRange(col, srcV3R64, 2);
00079 Core::Array::ProjectRange(tmp, srcV3R64, 3);
00080 Core::Array::Add(col, col, tmp);
00081
00082
00083 Core::Array::RecGauss(col, col, mSigma, mSigma, 0, 0, 3);
00084
00085 Array2dScalarReal64* crit = col;
00086
00087
00088 mStat->DoArray(crit);
00089
00090 Array2dScalarReal64* diff = 0;
00091 Core::Array::Sub(diff, mStat->GetMean(), crit);
00092 Core::Array::Abs(diff, diff);
00093 mWnd->UpdateView(view++, diff, "Stretch", mViewScale);
00094
00095 Array2dScalarUInt8* binIm = 0;
00096 Array2dScalarReal64* thr = 0;
00097 Core::Array::MulVal(thr, mStat->GetStDev(), 1.0);
00098 Core::Array::MaximumVal(thr, thr, mMinimumThres);
00099 Core::Array::GreaterThan(binIm, diff, thr);
00100 mWnd->UpdateView(view++, binIm, "Binary", mViewScale);
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 Array2dVec3UInt8* theBack = 0;
00118 Core::Array::Mul(theBack, srcWrap, binIm);
00119 mWnd->UpdateView(view++, theBack, "Direct", mViewScale);
00120 delete theBack;
00121
00122 delete diff;
00123 delete thr;
00124 delete binIm;
00125
00126 delete lum;
00127 delete col;
00128 delete tmp;
00129 delete srcV3R64;
00130 aSys.CheckMemoryUsageSinceMark(false);
00131 }
00132
00133 virtual void
00134 HandleNewKey(int c, int state)
00135 {
00136 if (c == 'r')
00137 Reset();
00138 if (c == 't')
00139 {
00140 mMinimumThres += 1;
00141 std::cout << "Minimum threshold at " << mMinimumThres << std::endl;
00142 }
00143 if (c == 'T')
00144 {
00145 mMinimumThres -= 1;
00146 std::cout << "Minimum threshold at " << mMinimumThres << std::endl;
00147 }
00148 }
00149
00150 private:
00151
00152 void
00153 Reset()
00154 {
00155 mMinimumThres = 5.0;
00156 mStat->Reset();
00157 }
00158
00159 Core::Database::DataDocument* mDataDoc;
00160 Window* mWnd;
00161 double mViewScale;
00162
00163 double mMinimumThres;
00164 double mSigma;
00165 int mBorderSize;
00166 Core::Array::Statistics<Array2dScalarReal64>* mStat;
00167
00168 };
00169
00170 }
00171 }
00172
00173 #endif