天天看点

VLfeat vl_slic使用方法及分割结果显示vl_slic的调用方法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 < 
       region = ;
       rate = ;
    end
    if nargin < 
       rate = ; 
    end
    im_single = im2single(im);
    segments = vl_slic(im_single, region, rate, 'verbose');

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

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

其中

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

继续阅读