• 大小: 1KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-23
  • 语言: 其他
  • 标签: image  segmen  

资源简介

Efficient Graph-Based Image Segmentation & k-means Image Segmentation

资源截图

代码片段和文件信息

Pic=imread(‘test.jpg‘);
Pic=im2double(Pic);
pic_size=size(Pic);
row=pic_size(1);%行
col=pic_size(2);%列
edge=zeros(row-1col-12);% 1 横 2竖
id =zeros(rowcol);

id_sum=ones(row*col1);
weight=0.5*ones(row*col1);
color=zeros(row*col3);
for i=1:row
    for j=1:col
        if i          edge(ij1)=sqrt(dot(Pic(ij:)-Pic(ij+1:)Pic(ij:)-Pic(ij+1:)));
          edge(ij2)=sqrt(dot(Pic(ij:)-Pic(i+1j:)Pic(ij:)-Pic(i+1j:)));
        end
        id(ij)=(i-1)*col+j;
        color(id(ij):)=Pic(ij:);
    end
end
[ab]=sort(edge(:));
[rpq]=ind2sub(size(edge)b);
n=size(r);
k=0.1;
for i=1:n
    if q(i)==1
      if id(r(i)p(i))~=id(r(i)p(i)+1)
          if edge(r(i)p(i)q(i))<=min(weight(id(r(i)p(i)))+k/id_sum(id(r(i)p(i)))weight(id(r(i)p(i)+1))++k/id_sum(id(r(i)p(i)+1)))
              id_sum(id(r(i)p(i)))=id_sum(id(r(i)p(i)))+id_sum(id(r(i)p(i)+1));
              weight(id(r(i)p(i)))=edge(r(i)p(i)q(i))+k/id_sum(id(r(i)p(i)));
              idx= id==id(r(i)p(i)+1); 
              id(idx)=id(r(i)p(i)); 
              
              
          end
      end
    end
    if q(i)==2
      if id(r(i)p(i))~=id(r(i)+1p(i))
          if edge(r(i)p(i)q(i))<=min(weight(id(r(i)p(i)))+k/id_sum(id(r(i)p(i)))weight(id(r(i)+1p(i)))+k/id_sum(id(r(i)+1p(i))))
               id_sum(id(r(i)p(i)))=id_sum(id(r(i)p(i)))+id_sum(id(r(i)+1p(i)));
              weight(id(r(i)p(i)))=edge(r(i)p(i)q(i))+k/id_sum(id(r(i)p(i)));
              idx= id==id(r(i)+1p(i)); 
              id(idx)=id(r(i)p(i)); 
              
               
          end
      end
    end
end
for i=1:row
    for j=1:col
        x=fix((id(ij)-1)/col)+1;
        y=id(ij)-(x-1)*col;
        Pic(ij:)=Pic(xy:);
    end
end


Pic=im2uint8(Pic);
imshow(Pic);




 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1861  2017-05-04 08:50  graph_based.m

     文件        973  2017-04-06 11:36  k_main.m

----------- ---------  ---------- -----  ----

                 2834                    2


评论

共有 条评论