Commit 4ec1d827 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #922 from cbalint13:slic

parents 46af5dc0 5d73f997
...@@ -1742,10 +1742,6 @@ inline void SuperpixelLSCImpl::PerformLSC( const int& itrnum ) ...@@ -1742,10 +1742,6 @@ inline void SuperpixelLSCImpl::PerformLSC( const int& itrnum )
&centerC1, &centerC2, m_nr_channels, m_chvec_max, &centerC1, &centerC2, m_nr_channels, m_chvec_max,
m_dist_coeff, m_color_coeff, m_stepx, m_stepy ) ); m_dist_coeff, m_color_coeff, m_stepx, m_stepy ) );
// parallel reduce structure
FeatureCenterDists fcd( m_chvec, m_W, m_klabels, m_nr_channels, m_chvec_max,
m_dist_coeff, m_color_coeff, m_stepx, m_stepy, m_numlabels );
// K-Means // K-Means
for( int itr = 0; itr < itrnum; itr++ ) for( int itr = 0; itr < itrnum; itr++ )
{ {
...@@ -1759,6 +1755,10 @@ inline void SuperpixelLSCImpl::PerformLSC( const int& itrnum ) ...@@ -1759,6 +1755,10 @@ inline void SuperpixelLSCImpl::PerformLSC( const int& itrnum )
m_nr_channels, m_chvec_max, m_dist_coeff, m_color_coeff, m_nr_channels, m_chvec_max, m_dist_coeff, m_color_coeff,
m_stepx, m_stepy ) ); m_stepx, m_stepy ) );
// parallel reduce structure
FeatureCenterDists fcd( m_chvec, m_W, m_klabels, m_nr_channels, m_chvec_max,
m_dist_coeff, m_color_coeff, m_stepx, m_stepy, m_numlabels );
// accumulate center distances // accumulate center distances
parallel_reduce( BlockedRange(0, m_width), fcd ); parallel_reduce( BlockedRange(0, m_width), fcd );
......
...@@ -732,17 +732,6 @@ struct SeedsCenters ...@@ -732,17 +732,6 @@ struct SeedsCenters
clustersize.assign(numlabels, 0); clustersize.assign(numlabels, 0);
} }
void ClearArrays( )
{
// refill with zero all arrays
for( int b = 0; b < nr_channels; b++ )
fill(sigma[b].begin(), sigma[b].end(), 0.0f);
fill(sigmax.begin(), sigmax.end(), 0.0f);
fill(sigmay.begin(), sigmay.end(), 0.0f);
fill(clustersize.begin(), clustersize.end(), 0);
}
SeedsCenters( const SeedsCenters& counter, Split ) SeedsCenters( const SeedsCenters& counter, Split )
{ {
*this = counter; *this = counter;
...@@ -1006,10 +995,7 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum ) ...@@ -1006,10 +995,7 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum )
// this is the variable value of M, just start with 10 // this is the variable value of M, just start with 10
vector<float> maxxy( m_numlabels, FLT_MIN ); vector<float> maxxy( m_numlabels, FLT_MIN );
// note: this is different from how usual SLIC/LKM works // note: this is different from how usual SLIC/LKM works
float xywt = float(m_region_size*m_region_size); const float xywt = float(m_region_size*m_region_size);
// parallel reduce structure
SeedsCenters sc( m_chvec, m_klabels, m_numlabels, m_nr_channels );
for( int itr = 0; itr < itrnum; itr++ ) for( int itr = 0; itr < itrnum; itr++ )
{ {
...@@ -1051,6 +1037,9 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum ) ...@@ -1051,6 +1037,9 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum )
// Recalculate the centroid and store in the seed values // Recalculate the centroid and store in the seed values
//----------------------------------------------------------------- //-----------------------------------------------------------------
// parallel reduce structure
SeedsCenters sc( m_chvec, m_klabels, m_numlabels, m_nr_channels );
// accumulate center distances // accumulate center distances
parallel_reduce( BlockedRange(0, m_width), sc ); parallel_reduce( BlockedRange(0, m_width), sc );
...@@ -1058,8 +1047,6 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum ) ...@@ -1058,8 +1047,6 @@ inline void SuperpixelSLICImpl::PerformSLICO( const int& itrnum )
parallel_for_( Range(0, m_numlabels), SeedNormInvoker( &m_kseeds, &sc.sigma, parallel_for_( Range(0, m_numlabels), SeedNormInvoker( &m_kseeds, &sc.sigma,
&sc.clustersize, &sc.sigmax, &sc.sigmay, &m_kseedsx, &m_kseedsy, m_nr_channels ) ); &sc.clustersize, &sc.sigmax, &sc.sigmay, &m_kseedsx, &m_kseedsy, m_nr_channels ) );
// refill arrays
sc.ClearArrays();
} }
} }
...@@ -1190,20 +1177,9 @@ struct SLICGrowInvoker : ParallelLoopBody ...@@ -1190,20 +1177,9 @@ struct SLICGrowInvoker : ParallelLoopBody
*/ */
inline void SuperpixelSLICImpl::PerformSLIC( const int& itrnum ) inline void SuperpixelSLICImpl::PerformSLIC( const int& itrnum )
{ {
vector< vector<float> > sigma(m_nr_channels);
for( int b = 0; b < m_nr_channels; b++ )
sigma[b].resize(m_numlabels, 0);
vector<float> sigmax(m_numlabels, 0);
vector<float> sigmay(m_numlabels, 0);
vector<int> clustersize(m_numlabels, 0);
Mat distvec( m_height, m_width, CV_32F ); Mat distvec( m_height, m_width, CV_32F );
float xywt = (m_region_size/m_ruler)*(m_region_size/m_ruler); const float xywt = (m_region_size/m_ruler)*(m_region_size/m_ruler);
// parallel reduce structure
SeedsCenters sc( m_chvec, m_klabels, m_numlabels, m_nr_channels );
for( int itr = 0; itr < itrnum; itr++ ) for( int itr = 0; itr < itrnum; itr++ )
{ {
...@@ -1225,15 +1201,16 @@ inline void SuperpixelSLICImpl::PerformSLIC( const int& itrnum ) ...@@ -1225,15 +1201,16 @@ inline void SuperpixelSLICImpl::PerformSLIC( const int& itrnum )
//----------------------------------------------------------------- //-----------------------------------------------------------------
// instead of reassigning memory on each iteration, just reset. // instead of reassigning memory on each iteration, just reset.
// parallel reduce structure
SeedsCenters sc( m_chvec, m_klabels, m_numlabels, m_nr_channels );
// accumulate center distances // accumulate center distances
parallel_reduce( BlockedRange(0, m_width), sc ); parallel_reduce( BlockedRange(0, m_width), sc );
// normalize centers // normalize centers
parallel_for_( Range(0, m_numlabels), SeedNormInvoker( &m_kseeds, &sigma, parallel_for_( Range(0, m_numlabels), SeedNormInvoker( &m_kseeds, &sc.sigma,
&clustersize, &sigmax, &sigmay, &m_kseedsx, &m_kseedsy, m_nr_channels ) ); &sc.clustersize, &sc.sigmax, &sc.sigmay, &m_kseedsx, &m_kseedsy, m_nr_channels ) );
// refill arrays
sc.ClearArrays();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment