//=========================================================================== /// GetLABXYSeeds_ForGivenStepSize /// /// The k seed values are taken as uniform spatial pixel samples. //=========================================================================== void SLIC::GetLABXYSeeds_ForGivenStepSize( vector<double>& kseedsl, vector<double>& kseedsa, vector<double>& kseedsb, vector<double>& kseedsx, vector<double>& kseedsy, const int& STEP, const bool& perturbseeds, const vector<double>& edgemag) { int numseeds(0); int n(0); //int xstrips = m_width/STEP; //int ystrips = m_height/STEP; int xstrips = (0.5+double(m_width)/double(STEP)); int ystrips = (0.5+double(m_height)/double(STEP)); int xerr = m_width - STEP*xstrips; int yerr = m_height - STEP*ystrips; double xerrperstrip = double(xerr)/double(xstrips); double yerrperstrip = double(yerr)/double(ystrips); int xoff = STEP/2; int yoff = STEP/2; //------------------------- numseeds = xstrips*ystrips; //------------------------- kseedsl.resize(numseeds); kseedsa.resize(numseeds); kseedsb.resize(numseeds); kseedsx.resize(numseeds); kseedsy.resize(numseeds); for( int y = 0; y < ystrips; y++ ) { int ye = y*yerrperstrip; for( int x = 0; x < xstrips; x++ ) { int xe = x*xerrperstrip; int i = (y*STEP+yoff+ye)*m_width + (x*STEP+xoff+xe); kseedsl[n] = m_lvec[i]; kseedsa[n] = m_avec[i]; kseedsb[n] = m_bvec[i]; kseedsx[n] = (x*STEP+xoff+xe); kseedsy[n] = (y*STEP+yoff+ye); n++; } } if(perturbseeds) { PerturbSeeds(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, edgemag); } }
//=========================================================================== /// GetLABXYSeeds_ForGivenK /// /// The k seed values are taken as uniform spatial pixel samples. //=========================================================================== void SLIC::GetLABXYSeeds_ForGivenK( vector<double>& kseedsl, vector<double>& kseedsa, vector<double>& kseedsb, vector<double>& kseedsx, vector<double>& kseedsy, const int& K, const bool& perturbseeds, const vector<double>& edgemag) { int sz = m_width*m_height; double step = sqrt(double(sz)/double(K)); int T = step; int xoff = step/2; int yoff = step/2; int n(0);int r(0); for( int y = 0; y < m_height; y++ ) { int Y = y*step + yoff; if( Y > m_height-1 ) break; for( int x = 0; x < m_width; x++ ) { //int X = x*step + xoff;//square grid int X = x*step + (xoff<<(r&0x1));//hex grid if(X > m_width-1) break; int i = Y*m_width + X; //_ASSERT(n < K); //kseedsl[n] = m_lvec[i]; //kseedsa[n] = m_avec[i]; //kseedsb[n] = m_bvec[i]; //kseedsx[n] = X; //kseedsy[n] = Y; kseedsl.push_back(m_lvec[i]); kseedsa.push_back(m_avec[i]); kseedsb.push_back(m_bvec[i]); kseedsx.push_back(X); kseedsy.push_back(Y); n++; } r++; } if(perturbseeds) { PerturbSeeds(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, edgemag); } }
//=========================================================================== /// GetLABXYSeeds_ForGivenStepSize /// /// The k seed values are taken as uniform spatial pixel samples. //=========================================================================== void SLIC::GetLABXYSeeds_ForGivenStepSize( vector<double>& kseedsl, vector<double>& kseedsa, vector<double>& kseedsb, vector<double>& kseedsx, vector<double>& kseedsy, const int& STEP, const bool& perturbseeds, const vector<double>& edgemag) { const bool hexgrid = false; int numseeds(0); int n(0); //int xstrips = m_width/STEP; //int ystrips = m_height/STEP; int xstrips = (0.5+double(m_width)/double(STEP)); int ystrips = (0.5+double(m_height)/double(STEP)); int xerr = m_width - STEP*xstrips; if(xerr < 0) { xstrips--; xerr = m_width - STEP*xstrips; } int yerr = m_height - STEP*ystrips; if(yerr < 0) { ystrips--; yerr = m_height- STEP*ystrips; } double xerrperstrip = double(xerr)/double(xstrips); double yerrperstrip = double(yerr)/double(ystrips); int xoff = STEP/2; int yoff = STEP/2; //------------------------- numseeds = xstrips*ystrips; //------------------------- kseedsl.resize(numseeds); kseedsa.resize(numseeds); kseedsb.resize(numseeds); kseedsx.resize(numseeds); kseedsy.resize(numseeds); for( int y = 0; y < ystrips; y++ ) { int ye = y*yerrperstrip; for( int x = 0; x < xstrips; x++ ) { int xe = x*xerrperstrip; int seedx = (x*STEP+xoff+xe); if(hexgrid) { seedx = x*STEP+(xoff<<(y&0x1))+xe; //for hex grid sampling seedx = min(m_width-1,seedx); } int seedy = (y*STEP+yoff+ye); int i = seedy*m_width + seedx; kseedsl[n] = m_lvec[i]; kseedsa[n] = m_avec[i]; kseedsb[n] = m_bvec[i]; kseedsx[n] = seedx; kseedsy[n] = seedy; n++; } } if(perturbseeds) { PerturbSeeds(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, edgemag); } }