VLfeat vl_slic使用方法及分割结果显示

vl_slic的调用方法

segments = vl_slic(im, region, rate);
  • im必须为single类型
  • region值越大,分割的块越大
  • rate越大,图像越”正方形”
  • 还有一些其他可选参数,具体参看vl_slic
  • 返回值segments是一个大小与im一样的矩阵,矩阵上相同的值,说明这些位置是属于同一个块的

vl_slic处理结果显示

vl_slic返回的结果不能直接用于显示,参考了vl_demo_slic的代码,这里给出一种显示结果的方法

function [segments] = vl_slic_test(im, region, rate)
% VL_SLIC_TEST show result of vl_slic
%   vl_slic only return the segments which is puzzled, 
%   this function use vl_grad to compute the edge of the segments, and
%   show the final image.
    if nargin < 2
       region = 10;
       rate = 1;
    end
    if nargin < 3
       rate = 1; 
    end
    im_single = im2single(im);
    segments = vl_slic(im_single, region, rate, 'verbose');

    figure(1); clf;
    % overaly segmentation
    [sx, sy] = vl_grad(double(segments), 'type', 'forward');
    s = find(sx | sy);
    imp = im;

    num_of_pixel = numel(im(:,:,1));
    % (r g b) = 0, black line
    imp([s s+num_of_pixel s+2*num_of_pixel]) = 0;
    imshow(imp);

其中

imp([s s+num_of_pixel s+2*num_of_pixel]) = 0;

将rgb都设置为0(黑色),块与块的边界的颜色可以进行设置。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值