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

void Impala::Core::Array::ColorSegmentation ( Array2dVec3UInt8 *&  dst,
Array2dVec3Real64 *  im,
ColorSegmentationAlgorithm  segAlg,
ColorSegmentationInvariant  invariantType,
double  minRegionFraction,
double  threshold,
bool  useGauss = false,
std::vector< Array2dVec3UInt8 * > *  dispList = 0 
) [inline]

Definition at line 70 of file ColorSegmentation.h.

References ArrayListDelete(), ArrayListExport(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CH(), ColorGaborResponses(), ColorGaussResponses(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CPB(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CW(), extractRegions(), labelimg(), Impala::Core::Matrix::MatE(), Impala::Core::Matrix::MatFeatureNormalization(), Impala::Core::Matrix::MatKLM(), Impala::Core::Matrix::MatKMeans(), Impala::Core::Matrix::MatNrCol(), Impala::Core::Matrix::MatNrRow(), Impala::Core::Matrix::MatTranspose(), mergeRegions(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::PB(), refinery(), relabel(), Impala::Core::Matrix::VecE(), and Impala::Core::Matrix::VecNrElem().

Referenced by Impala::Application::Im::DoColorSegmentation(), Impala::Application::Src::WindowSrc::HandleNewFrame(), and Impala::Core::Test::TestColorSegmentation::Run().

00076 {
00077 bool vv = false;
00078 if (vv) std::cout << "start ColorSegmentation" << std::endl;
00079     if (dst == 0)
00080         dst = ArrayCreate<Array2dVec3UInt8>(im->CW(), im->CH());
00081     Timer timer(1);
00082     timer.Start();
00083     std::vector<Array2dScalarReal64*> respList;
00084     if (useGauss)
00085         respList = ColorGaussResponses(im);
00086     else
00087         respList = ColorGaborResponses(im, segAlg, invariantType);
00088     //WriteRawList(respList, std::string("resp.raw"), true);
00089 
00090 if (vv) std::cout << " making response matrix" << std::endl;
00091 
00092     typedef Array2dScalarReal64 Mat;
00093     typedef VecScalarReal64 Vec;
00094     int nrFeat = respList.size();
00095     int nrPixels = respList[0]->CW() * respList[0]->CH();
00096     int nrPcaDim = 4;
00097 
00098     double* data = ArrayListExport(respList);
00099     ArrayListDelete(&respList);
00100 
00101     Mat* mTmp = MatCreate<Mat>(nrFeat, nrPixels, data);
00102     //WriteRaw(mTmp, "abc_feat.raw", true);
00103     Mat* m = MatTranspose(mTmp);
00104     delete mTmp;
00105 
00106 if (vv) std::cout << "time: " << timer.SplitTime() << " PCA " << std::endl;
00107     // reduce to nrPcaDim dimensions with PCA (if necessary)
00108     if (MatNrCol(m) > nrPcaDim)
00109     {
00110         mTmp = MatKLM(m, nrPcaDim);
00111         delete m;
00112         m = mTmp;
00113     }
00114 
00115 if (vv) std::cout << "time: " << timer.SplitTime() << " feature_normalization " << std::endl;
00116         // normalize 
00117      MatFeatureNormalization(m); 
00118 
00119 if (vv) std::cout << "time: " << timer.SplitTime() << " kmeans " << std::endl;
00120 
00121         // k-means
00122     int nrClusters = nrPixels/2500;
00123     Mat* clusters = MatCreate<Mat>(nrClusters, MatNrCol(m));
00124     Vec* clusterMap = VecCreate<Vec>(nrPixels);
00125     VecScalarInt32* vectorsInC = VecCreate<VecScalarInt32>(nrClusters);
00126     int clustersFound;
00127     MatKMeans(m, clusters, clusterMap, 25, false, clustersFound, vectorsInC);
00128     delete clusters;
00129 if (vv)
00130 for (int i=0 ; i<nrClusters ; i++)
00131 {
00132     int nr = *VecE(vectorsInC, i);
00133     std::cout << "cluster " << i << " has " << nr//*VecE(vectorsInC, i) 
00134           << " vectors" << std::endl;
00135 }
00136     delete vectorsInC;
00137 
00138 // mMat is "wrapper" since Matrix dtor commented
00139 MatrixDouble mMat(MatNrRow(m), MatNrCol(m), MatE(m));
00140 
00141     VectorDouble clusterMapMat(VecNrElem(clusterMap), VecE(clusterMap), false);
00142     delete clusterMap;
00143 
00144 if (vv) std::cout << "time: " << timer.SplitTime() << " Doing region stuff " << std::endl;
00145 if (dispList != 0)
00146 {
00147     Array2dVec3UInt8* dIm = ArrayCreate<Array2dVec3UInt8>(im->CW(), im->CH());
00148     labelimg(dIm->PB(), clusterMapMat, im->CW(), im->CH());
00149     dispList->push_back(dIm);
00150 }
00151 
00152         // get the regions
00153     pixgroup *rg = new pixgroup[nrClusters];
00154     extractRegions(rg, nrClusters, clusterMapMat, mMat);
00155 
00156         // merge regions below threshold
00157     mergeRegions(rg, nrClusters, clusterMapMat, mMat, im->CW(), im->CH(),
00158                  threshold) ;
00159 if (dispList != 0)
00160 {
00161     Array2dVec3UInt8* dIm = ArrayCreate<Array2dVec3UInt8>(im->CW(), im->CH());
00162     labelimg(dIm->PB(), clusterMapMat, im->CW(), im->CH());
00163     dispList->push_back(dIm);
00164 }
00165 
00166         // UN-label region borders, and the image border
00167         // minRegionFraction indicates the minimal size of a region in a percentage
00168     relabel(clusterMapMat, im->CW(), im->CH(), rg, nrClusters, 3,
00169             nrPixels * minRegionFraction);
00170 if (dispList != 0)
00171 {
00172     Array2dVec3UInt8* dIm = ArrayCreate<Array2dVec3UInt8>(im->CW(), im->CH());
00173     labelimg(dIm->PB(), clusterMapMat, im->CW(), im->CH());
00174     dispList->push_back(dIm);
00175 }
00176 
00177         // region growing
00178     refinery(clusterMapMat, mMat, rg, nrClusters, im->CW(), im->CH());
00179 
00180         // create colors for a region
00181     labelimg(dst->CPB(), clusterMapMat, im->CW(), im->CH());
00182 
00183     delete m;
00184     delete[] rg;
00185 if (vv) std::cout << "time: " << timer.SplitTime() << " Done " << std::endl;
00186 }

Here is the call graph for this function:


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