SLIC Superpixels 算法代码学习笔记

1.主程序入口
  • 下面的程序就是超像素生成的函数入口
slic.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(img, width, height, labels, numlabels, m_spcount, m_compactness);
这里有几个特别的参数需要说明:
  1. slic:SLIC slic; 是一个SLIC类
  2. labels:int* labels = new int[sz];一张标签图,和图像大小一致,用于标记每个像素的标签值;sz=width*height,即一张图像的像素总数。
  3. numlabels:int numlabels(0);是图像最终分成的类数,即最终生成的超像素个数,在这里被初始化为0。
  4. m_spcount: 客户从界面输入的值,即初始化的种子个数,但是SLIC算法中不一定每个种子最终都能得一个超像素,由于某些因素可能被其他超像素合并。若种子数不符合规定,则通过(总像素值SZ)/(每个超像素默认大小200)获得种子数:if (m_spcount < 20 || m_spcount > sz/4) m_spcount = sz/200;
  5. m_compactness:if(m_compactness < 1.0 || m_compactness > 80.0) m_compactness = 20.0;这个值也是有用户设定的,是颜色特征和XY坐标特征之间的紧密度比例,20这个值效果往往不错。
  • 该函数的定义
void SLIC::DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(
    unsigned int *                                   ubuff,//img
   const int                                         width,
    const int                                        height,
    int*&                                           klabels,//labels
    int&                                            numlabels, //
    const int &                                      K, //初始化的种子 m_spcount
    const double &                                   compactness) // m_compactness空间参数转换的权重值
{
    const int superpixelsize = 0.5+double(width*height)/ double(K);
    DoSuperpixelSegmentation_ForGivenSuperpixelSize(ubuff,width,height,klabels,numlabels,superpixelsize,compactness);
}
  1. superpixelsize:超像素的大小,即每个超像素中包含的像素值
  2. DoSuperpixelSegmentation_ForGivenSuperpixelSize函数中完成了超像素生成的功能
  3. const int STEP = sqrt(double(superpixelsize))+0.5;这个变量很关键,是种子点的跨度。
2.子程序流程
DoSuperpixelSegmentation_ForGivenSuperpixelSize函数中主要包含以下函数:
  • DoRGBtoLABConversion(ubuff, m_lvec, m_avec, m_bvec); 
     将RGB图像转换为LAB图像。
  • GetLABXYSeeds_ForGivenStepSize(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, STEP, perturbseeds, edgemag);
           均匀分布种子点,将种子点的5维特征值LABXY作为分类的中心点特征值存入 kseeds向量中。
  • PerformSuperpixelSLIC(kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, klabels, STEP, edgemag,compactness);
          对整张图像进行局部的K-Means聚类,生成超像素。这是超像素生成的关键步骤,也耗时最多。
  • 7
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值