# 5 麦片

050

1主题 0最佳答案

 %%%%这是一个关于超像素分割的代码  从聚类尺寸哪里开始出现zeros 而且总是报错 求解决。 function klabels = PerformSuperpixelSLIC(img_Lab, kseedsl, kseedsa, kseedsb, kseedsx, kseedsy, STEP, compactness) [m_height, m_width, m_channel] = size(img_Lab); numseeds = size(kseedsl); img_Lab = double(img_Lab); %像素标签格式为(x, y) (行, 列) klabels = zeros(m_height, m_width); %聚类尺寸 clustersize = zeros((numseeds, 1); inv = zeros(numseeds, 1); sigmal = zeros(numseeds, 1); sigmaa = zeros(numseeds, 1); sigmab = zeros(numseeds, 1); sigmax = zeros(numseeds, 1); sigmay = zeros(numseeds, 1); invwt = 1/((double(STEP)/double(compactness))*(double(STEP)/double(compactness))); %invwt = double(compactness)/double(STEP); distvec = 100000*ones(m_height, m_width); numk = numseeds; for itr = 1: 10   %迭代次数     sigmal = zeros(numseeds, 1);     sigmaa = zeros(numseeds, 1);     sigmab = zeros(numseeds, 1);     sigmax = zeros(numseeds, 1);     sigmay = zeros(numseeds, 1);     clustersize = zeros(numseeds, 1);     inv = zeros(numseeds, 1);     distvec = double(100000*ones(m_height, m_width));     %根据当前种子点信息计算每一个像素的归属     for n = 1: numk         y1 = max(1, kseedsy(n, 1)-STEP);         y2 = min(m_height, kseedsy(n, 1)+STEP);         x1 = max(1, kseedsx(n, 1)-STEP);         x2 = min(m_width, kseedsx(n, 1)+STEP);         %按像素计算距离         for y = y1: y2             for x = x1: x2                 %dist_lab = abs(img_Lab(y, x, 1)-kseedsl(n))+abs(img_Lab(y, x, 2)-kseedsa(n))+abs(img_Lab(y, x, 3)-kseedsb(n));                 dist_lab = (img_Lab(y, x, 1)-kseedsl(n, 1))^2+(img_Lab(y, x, 2)-kseedsa(n, 1))^2+(img_Lab(y, x, 3)-kseedsb(n, 1))^2;                 dist_xy = (double(y)-kseedsy(n, 1))*(double(y)-kseedsy(n, 1)) + (double(x)-kseedsx(n, 1))*(double(x)-kseedsx(n, 1));                 %dist_xy = abs(y-kseedsy(n)) + abs(x-kseedsx(n));                 %距离 = lab色彩空间距离 + 空间距离权重×空间距离                 dist = dist_lab + dist_xy*invwt;                 %在周围最多四个种子点中找到最相似的 标记后存入klabels                 %m = (y-1)*m_width+x;                 if (dist

 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页