1

我觉得这是一个相当简单的问题,但我似乎无法弄清楚。我正在尝试vl_slic在 MATLAB 中使用 VLFEAT 的函数,并且正在使用此页面上使用的文档:http ://www.vlfeat.org/overview/slic.html

我无法弄清楚的是如何显示和覆盖相应的段的图像。我目前拥有的是这样的:

img = imread('slic_image.jpg');
regionSize = 30 ;
regularizer = 1  ;
vl_setup
segments = vl_slic(single(img), regionSize, regularizer);
imshow(img);hold on;
imshow(segments);

但我看到的只是黑色图像。我不确定如何让我的输出看起来更像上面网页上的输出。

4

1 回答 1

1

我目前无法访问 MatLab - 所以没有机会实际尝试它 - 但请查看以下功能。根据 VLFeat 的源代码,该函数vl_slic将标签作为矩阵返回:

% VL_SLIC  SLIC superpixels
%   SEGMENTS = VL_SLIC(IM, REGIONSIZE, REGULARIZER) extracts the SLIC
%   superpixes [1] from image IM. REGIONSIZE is the starting size of
%   the superpixels and REGULARIZER is the trades-off appearance for
%   spatial regularity when clustering (a larger value results in more
%   spatial regularization). SEGMENTS is a UINT32 array containing the
%   superpixel identifier for each image pixel.

函数draw_contours定义如下:

function [contourImg] = draw_contours(labels, img)
% function [contourImg] = draw_contours(labels, img)
%
% David Stutz <david.stutz@rwth-aachen.de>

    rows = size(img, 1);
    cols = size(img, 2);

    contourImg = img;
    for i = 1: rows
        for j = 1: cols
            label = labels(i, j);
            labelTop = 0;
            labelBottom = 0;
            labelLeft = 0;
            labelRight = 0;

            if i > 1
                labelTop = labels(i - 1, j);
            end;
            if j > 1
                labelLeft = labels(i, j - 1);
            end;
            if i < rows
                labelBottom = labels(i + 1, j);
            end;
            if j < cols
                labelRight = labels(i, j + 1);
            end;

            if labelTop ~= 0 && labelTop ~= label
                contourImg(i, j, 1) = 0;
                contourImg(i, j, 2) = 0;
                contourImg(i, j, 3) = 0;
            end;
            if labelLeft ~= 0 && labelLeft ~= label
                contourImg(i, j, 1) = 0;
                contourImg(i, j, 2) = 0;
                contourImg(i, j, 3) = 0;
            end;
            if labelBottom ~= 0 && labelBottom ~= label
                contourImg(i, j, 1) = 0;
                contourImg(i, j, 2) = 0;
                contourImg(i, j, 3) = 0;
            end;
            if labelRight ~= 0 && labelRight ~= label
                contourImg(i, j, 1) = 0;
                contourImg(i, j, 2) = 0;
                contourImg(i, j, 3) = 0;
            end;
        end;
    end;
end

给定图像img = imread('path/to/image');,只需提取超像素,然后绘制轮廓图像:

img = imread('path/to/image');
labels = vl_slic(img, regionSize, regularizer);
contourImg = draw_contours(labels, img);
imshow(contourImg);

该功能draw_contours已使用 Turbopixels 超像素 [2] 进行了测试。下图显示了 VLFeat 的 SLIC [3] 实现的结果,它使用 C++ 实现的用于绘制轮廓的类似函数,以及使用 VLFeat 的 C 接口提取的超像素。C++ 源代码可以在 GitHub 上找到:https ://github.com/davidstutz/vlfeat-slic-example

使用 VLFeat 的实现提取的 SLIC 超像素,正则化设置为 1000,区域大小设置为 20。

  • [2] A. Levinshtein、A. Stere、KN Kutulakos、DJ Fleet、SJ Dickinson、K. Siddiqi。Turbopixels:使用几何流的快速超像素。IEEE Transactions on Pattern Analysis and Machine Intelligence,第 2290 – 2297 页,2009。
  • [3] R. Achanta、A. Shaji、K. Smith、A. Lucchi、P. Fua、S. Susstrunk。SLIC 超像素。技术报告,EPFL,洛桑,2010 年。
于 2014-07-27T19:45:58.240 回答