第一范文网 - 专业文章范例文档资料分享平台

SLIC超像素分割算法和目前超像素算法的比较代码实现 - 图文 (6)

来源:用户分享 时间:2020-06-09 本文由远水孤云 分享 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

//=========================================================================== /// GetKValues_LABXYZ ///

/// The k seed values are taken as uniform spatial pixel samples.

//=========================================================================== void SLIC::GetKValues_LABXYZ( {

const bool hexgrid = false;

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;} int zerr = m_depth - STEP*zstrips;if(zerr < 0){zstrips--;zerr = m_depth - STEP*zstrips;}

int xoff = STEP/2; int yoff = STEP/2; int zoff = STEP/2;

double xerrperstrip = double(xerr)/double(xstrips); double yerrperstrip = double(yerr)/double(ystrips); double zerrperstrip = double(zerr)/double(zstrips); int xstrips = (0.5+double(m_width)/double(STEP)); int ystrips = (0.5+double(m_height)/double(STEP)); int zstrips = (0.5+double(m_depth)/double(STEP)); int numseeds(0); int n(0);

vector& vector& vector& vector& vector& vector&

kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, kseedsz, STEP)

if(perturbseeds) { }

PerturbSeeds(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, edgemag);

const int&

}

//-------------------------

numseeds = xstrips*ystrips*zstrips; //------------------------- kseedsl.resize(numseeds); kseedsa.resize(numseeds); kseedsb.resize(numseeds); kseedsx.resize(numseeds); kseedsy.resize(numseeds); kseedsz.resize(numseeds);

for( int z = 0; z < zstrips; z++ ) { }

int ze = z*zerrperstrip; int d = (z*STEP+zoff+ze);

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_lvecvec[d][i]; kseedsa[n] = m_avecvec[d][i]; kseedsb[n] = m_bvecvec[d][i]; kseedsx[n] = (x*STEP+xoff+xe); kseedsy[n] = (y*STEP+yoff+ye); kseedsz[n] = d; n++;

//=========================================================================== /// PerformSuperpixelSLIC ///

/// Performs k mean segmentation. It is fast because it looks locally, not /// over the entire image.

//=========================================================================== void SLIC::PerformSuperpixelSLIC(

vector& vector& vector& vector& vector&

M)

kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, STEP,

int*& klabels,

const int& {

const double&

const vector& edgemag,

int sz = m_width*m_height; const int numk = kseedsl.size(); //---------------- int offset = STEP; //----------------

vector clustersize(numk, 0);

vector inv(numk, 0);//to store 1/clustersize[k] values vector sigmal(numk, 0); vector sigmaa(numk, 0); vector sigmab(numk, 0); vector sigmax(numk, 0); vector sigmay(numk, 0); vector distvec(sz, DBL_MAX); double invwt = 1.0/((STEP/M)*(STEP/M)); int x1, y1, x2, y2; double l, a, b; double dist; double distxy;

for( int itr = 0; itr < 10; itr++ ) {

distvec.assign(sz, DBL_MAX); for( int n = 0; n < numk; n++ ) {

kseedsy[n]-offset);

kseedsy[n]+offset); kseedsx[n]-offset);

//if(STEP < 8) offset = STEP*1.5;//to prevent a crash due to a very small step size

y1 = max(0.0, x1 = max(0.0,

y2 = min((double)m_height,

x2 = min((double)m_width,

sigmal.assign(numk, 0); sigmaa.assign(numk, 0); }

}

}

if( dist < distvec[i] ) { }

distvec[i] = dist; klabels[i] = n;

distxy =

dist =

l = m_lvec[i]; a = m_avec[i]; b = m_bvec[i];

for( int y = y1; y < y2; y++ ) {

for( int x = x1; x < x2; x++ ) {

int i = y*m_width + x;

kseedsx[n]+offset);

(l - kseedsl[n])*(l - kseedsl[n]) + (a - kseedsa[n])*(a - kseedsa[n]) + (b - kseedsb[n])*(b - kseedsb[n]);

(x - kseedsx[n])*(x - kseedsx[n]) +

(y - kseedsy[n])*(y - kseedsy[n]);

//------------------------------------------------------------------------

dist += distxy*invwt;//dist = sqrt(dist) + sqrt(distxy*invwt);//this is

more exact

//------------------------------------------------------------------------

//----------------------------------------------------------------- // Recalculate the centroid and store in the seed values

//----------------------------------------------------------------- //instead of reassigning memory on each iteration, just reset.

sigmab.assign(numk, 0); sigmax.assign(numk, 0); sigmay.assign(numk, 0); clustersize.assign(numk, 0);

//------------------------------------ //edgesum.assign(numk, 0);

//------------------------------------ {int ind(0);

for( int r = 0; r < m_height; r++ ) { }}

{for( int k = 0; k < numk; k++ ) { }}

{for( int k = 0; k < numk; k++ ) {

kseedsl[k] = sigmal[k]*inv[k]; kseedsa[k] = sigmaa[k]*inv[k]; kseedsb[k] = sigmab[k]*inv[k]; kseedsx[k] = sigmax[k]*inv[k]; kseedsy[k] = sigmay[k]*inv[k];

//------------------------------------ //edgesum[k] *= inv[k];

if( clustersize[k] <= 0 ) clustersize[k] = 1;

inv[k] = 1.0/clustersize[k];//computing inverse now to multiply, than divide later for( int c = 0; c < m_width; c++ ) { }

sigmal[klabels[ind]] += m_lvec[ind]; sigmaa[klabels[ind]] += m_avec[ind]; sigmab[klabels[ind]] += m_bvec[ind]; sigmax[klabels[ind]] += c; sigmay[klabels[ind]] += r;

//------------------------------------ //edgesum[klabels[ind]] += edgemag[ind]; //------------------------------------ clustersize[klabels[ind]] += 1.0; ind++;

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新IT计算机SLIC超像素分割算法和目前超像素算法的比较代码实现 - 图文 (6)全文阅读和word下载服务。

SLIC超像素分割算法和目前超像素算法的比较代码实现 - 图文 (6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/wenku/1078828.html(转载请注明文章来源)
热门推荐
Copyright © 2018-2022 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top