Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

void Impala::Core::Array::ColorMoments::FillMomentCache ( Array2dVec3Real64 rgb,
int  order,
int  degree,
bool  useBinaryMask = false,
Array2dScalarReal64 binaryMask = 0,
bool  blur = true,
double  sigma = 10.0 
) [inline]

Definition at line 67 of file ColorMomentsKoen.h.

References Impala::Core::Array::ArraySet< ArrayT >::Array(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CH(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CW(), mMomentCache, mShiftX, mShiftY, Impala::Core::Array::Mul(), Impala::Core::Array::PixSum(), Impala::Core::Array::ProjectRange(), Impala::Core::Array::RecGauss(), Impala::Core::Array::Set(), Impala::Core::Array::SetVal(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::SetValue(), and Impala::Application::DemoCamera2d::sigma.

Referenced by GetInvariants(), and GetMoments().

00068     {
00069         /* the binary mask should contain 0/1's only; it can be used to exclude
00070            certain pixels from rgb and should have the same size */
00071     
00072         /* clear the moment cache - just in case */
00073         mMomentCache.clear();
00074 
00075         Real64 TotalPixels = rgb->CW()*rgb->CH();
00076         if(useBinaryMask) {
00077             /* the total number of pixels is different */
00078             TotalPixels = PixSum(binaryMask);
00079         }
00080         
00081         ArraySet<Array2dScalarReal64>* X=new ArraySet<Array2dScalarReal64>(order+1);
00082         ArraySet<Array2dScalarReal64>* Y=new ArraySet<Array2dScalarReal64>(order+1);
00083         
00084         ArraySet<Array2dScalarReal64>* R=new ArraySet<Array2dScalarReal64>(degree+1);
00085         ArraySet<Array2dScalarReal64>* G=new ArraySet<Array2dScalarReal64>(degree+1);
00086         ArraySet<Array2dScalarReal64>* B=new ArraySet<Array2dScalarReal64>(degree+1);
00087         
00088         X->Array(0)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00089         Y->Array(0)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00090         R->Array(0)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00091         G->Array(0)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00092         B->Array(0)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00093     
00094         //Oth order/degree values are all 1;
00095         SetVal(X->Array(0),1);
00096         SetVal(Y->Array(0),1);
00097         SetVal(R->Array(0),1);
00098         SetVal(G->Array(0),1);
00099         SetVal(B->Array(0),1);
00100     
00101         //1st order/degree values are same with corresponding vectors
00102         if(order > 0) {
00103             // only compute (and allocate) these if they are needed
00104             X->Array(1)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00105             Y->Array(1)=new Array2dScalarReal64(rgb->CW(),rgb->CH(),0,0);
00106             for(int i=0;i<rgb->CW();i++) {
00107                 for(int j=0;j<rgb->CH();j++) {
00108                     X->Array(1)->SetValue(i+mShiftX+1,i,j);
00109                     Y->Array(1)->SetValue(j+mShiftY+1,i,j);
00110                 }
00111             }
00112         }
00113 
00114         ProjectRange(R->Array(1),rgb,1);
00115         ProjectRange(G->Array(1),rgb,2);
00116         ProjectRange(B->Array(1),rgb,3);
00117         
00118         if(blur){
00119             Array2dScalarReal64* tmp=0;
00120             RecGauss(tmp,R->Array(1),sigma,sigma,0,0,1);
00121             Set(R->Array(1),tmp);
00122             delete tmp;tmp=0;
00123             RecGauss(tmp,G->Array(1),sigma,sigma,0,0,1);
00124             Set(G->Array(1),tmp);
00125             delete tmp;tmp=0;
00126             RecGauss(tmp,B->Array(1),sigma,sigma,0,0,1);
00127             Set(B->Array(1),tmp);
00128             delete tmp;tmp=0;
00129         }
00130     
00131         for(int o=2;o<=order;o++){
00132             Mul(X->Array(o),X->Array(o-1),X->Array(1));
00133             Mul(Y->Array(o),Y->Array(o-1),Y->Array(1));
00134         }
00135         for(int d=2;d<=degree;d++){
00136             Mul(R->Array(d),R->Array(d-1),R->Array(1));
00137             Mul(G->Array(d),G->Array(d-1),G->Array(1));
00138             Mul(B->Array(d),B->Array(d-1),B->Array(1));
00139         }
00140         for(int o=0;o<=order;o++){
00141             for (int p=0;p<=o;p++){
00142                 for (int q=0;q<=o;q++){
00143                     if( p+q == o) {
00144                         for(int d=0;d<=degree;d++){
00145                             for(int r=0;r<=d;r++){
00146                                 for(int g=0;g<=d;g++){
00147                                     for(int b=0;b<=d;b++){
00148                                         if(r+g+b==d){
00149                                             Array2dScalarReal64* m = 0;
00150                                             Set(m,R->Array(r));
00151                                             if(g!=0)
00152                                                 Mul(m,m,G->Array(g));
00153                                             if(b!=0)
00154                                                 Mul(m,m,B->Array(b));
00155                                             if(p!=0)
00156                                                 Mul(m,m,X->Array(p));
00157                                             if(q!=0)
00158                                                 Mul(m,m,Y->Array(q));
00159                                             if(useBinaryMask) {
00160                                                 /* TotalPixels has been adapted above, now apply the mask */
00161                                                 Mul(m,m,binaryMask);
00162                                             }
00163                                             /*
00164                                             WriteRaw(R->Array(r), "r.raw", 0);
00165                                             WriteRaw(G->Array(g), "g.raw", 0);
00166                                             WriteRaw(B->Array(b), "b.raw", 0);
00167                                             WriteRaw(X->Array(p), "x.raw", 0);
00168                                             WriteRaw(Y->Array(q), "y.raw", 0);
00169                                             WriteRaw(binaryMask, "binarymask.raw", 0);
00170                                             WriteRaw(m, "m.raw", 0);
00171                                             std::cout << rgb->CW() << " " << rgb->CH() << " "<< r << g << b << p << q << std::endl;
00172                                             std::cout << TotalPixels << " " << PixSum(m) << " " << std::endl; */
00173                                             Real64 moment = PixSum(m)/TotalPixels;
00174                                             //std::cout << moment << std::endl;
00175                                             delete m;
00176                                             mMomentCache.push_back(ColorMoment(p,q,r,g,b,moment));
00177                                         }
00178                                     }
00179                                 }
00180                             }
00181                         }
00182                     }
00183                 }
00184             }
00185         }
00186         for(int o=0;o<=order;o++){
00187             delete X->Array(o);
00188             delete Y->Array(o);
00189         }
00190         for(int d=0;d<=degree;d++){
00191             delete R->Array(d);
00192             delete G->Array(d);
00193             delete B->Array(d);
00194         }
00195         delete X,Y,R,G,B;
00196     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:17:17 2011 for ImpalaSrc by  doxygen 1.5.1