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

void Impala::Core::Array::refinery ( VectorDouble &  clusterMap,
MatrixDouble &  m,
pixgroup *  rg,
int  nrClusters,
int  width,
int  height 
)

Definition at line 551 of file ColorSegmentation.h.

References BORDER, Impala::Core::Array::pixgroup::cov, Impala::Core::Matrix::MatrixTem< C >::covariance(), Impala::Core::Matrix::MatrixTem< C >::getRow(), Impala::Core::Array::pixgroup::idx, Impala::Core::Array::pixgroup::m, Impala::Core::Matrix::MatrixTem< C >::nCol(), Impala::Core::Array::pixgroup::nrPixInGroup, PROCESSED, UNLABELED, and updateMean().

Referenced by ColorSegmentation().

00553 {
00554 
00555 //  printf("refinery") ;
00556     int imsize = width*height;
00557     int i;
00558     int x,y,k;
00559     int d[4] = {1, -width, -1, width}; 
00560     VectorDouble pixstate(imsize);
00561 
00562     VectorDouble vec(m.nCol());
00563     double val ;
00564     std::list<long> boundarylist;
00565     std::list<long> *mylist = new std::list<long>[imsize];
00566 
00567     //now initialize for region growing
00568     for (i=0; i<nrClusters; i++) rg[i].nrPixInGroup = 0;
00569 
00570     for (i=0; i<width; i++) pixstate[i] = BORDER; //over the border
00571 
00572     for (y=1; y<height-1; y++) 
00573     {
00574         pixstate[i++] = BORDER;
00575         for (x=1; x<width-1; x++)
00576         {
00577             if (clusterMap[i]!=UNLABELED)
00578             {
00579                 int l = clusterMap[i];
00580                 long n = rg[l].nrPixInGroup;
00581                 rg[l].idx[n] = i; //add pixel's index
00582                 rg[l].nrPixInGroup++;
00583                 pixstate[i] = PROCESSED;
00584             }
00585             else //check adjacency (just on boundary or not)
00586             {
00587                 int adjflag = 0;
00588                 for (int u=0; u<4; u++) if (clusterMap[i+d[u]]!=UNLABELED)
00589                 {
00590                     boundarylist.push_back(i); //store the boundary pixel
00591                     pixstate[i] = clusterMap[i+d[u]];
00592                     adjflag = 1;
00593                     break;
00594                 }
00595                 if (!adjflag) pixstate[i] = UNLABELED;
00596             }
00597             i++;
00598         }
00599         pixstate[i++] = BORDER;
00600     }
00601     for (;i<imsize; i++) pixstate[i] = BORDER;
00602 
00603     for (i=0; i<nrClusters; i++)
00604     {
00605         rg[i].label = i;
00606 
00607         MatrixDouble rgPixMatrix(rg[i].nrPixInGroup,m.nCol());
00608         for(int j=0;j<rg[i].nrPixInGroup;j++) 
00609             rgPixMatrix.setRow(j, m.getRow(rg[i].idx[j]) ) ;
00610 
00611         VectorDouble means ;
00612         rg[i].cov = rgPixMatrix.covariance(means) ;
00613         rg[i].m = means ;
00614 
00615     }
00616 
00617     //now initialize for region growing
00618     int counter=0 ;
00619     while(!boundarylist.empty())
00620     {
00621         i = boundarylist.front();
00622 
00623         boundarylist.pop_front();
00624         clusterMap[i] = pixstate[i];
00625 
00626         int l = clusterMap[i];
00627         for (k=0; k<m.nCol(); k++) {
00628             vec[k] = rg[l].m[k] - m[i][k]; //mean[l]-this pix i
00629 
00630         }
00631         val = vec * vec ;
00632         int b = (int)(val*200); //scale
00633         if (b>=imsize) b=imsize-1;
00634         mylist[b].push_back(i);
00635         counter++;
00636     }
00637     //now grow the regions
00638     int nmin = 0;
00639     while (1)
00640     {
00641         for (; nmin<imsize && mylist[nmin].empty();nmin++);
00642         if (nmin==imsize) break; //done
00643 
00644         while(!mylist[nmin].empty())
00645         {
00646             i = mylist[nmin].front();
00647             mylist[nmin].pop_front();
00648             clusterMap[i] = pixstate[i];
00649             pixstate[i] = PROCESSED;
00650             //update region
00651             int l = clusterMap[i]; //i is added to region clusterMap[i]
00652             rg[l].idx[rg[l].nrPixInGroup] = i; //add pixel;
00653             rg[l].nrPixInGroup++;               
00654             updateMean(m, rg[l],i);
00655             for (int u=0; u<4; u++) if (pixstate[i+d[u]]==UNLABELED) //extended
00656             {
00657                 int newid = i + d[u];
00658                 for (k=0; k<m.nCol(); k++) {
00659                     vec[k] = rg[l].m[k] - m[newid][k]; //mean[l]-this pix i
00660                 }
00661 
00662                 val = vec * vec ;
00663                 int b = (int)(val*200);
00664                 if (b>=imsize) b=imsize-1;
00665                 mylist[b].push_back(newid);
00666                 pixstate[newid] = clusterMap[i];
00667                 if (b<nmin) nmin = b;
00668             }
00669         } //while
00670     }
00671 
00672     delete[] mylist;
00673 
00674 }

Here is the call graph for this function:


Generated on Fri Mar 19 10:56:22 2010 for ImpalaSrc by  doxygen 1.5.1