【问题标题】:find boundary co ordinates of image in matlab在matlab中找到图像的边界坐标
【发布时间】:2015-05-14 05:33:45
【问题描述】:

我想在matlab中以逆时针的方式找到手部轮廓的边界点(坐标)。即从任意点开始逆时针遍历并存储坐标。

简单的行列扫描没有用,因为坐标必须是 8 连接的。

请帮帮我

【问题讨论】:

    标签: matlab coordinates boundary


    【解决方案1】:

    你可以用imcontour得到轮廓,然后fliplr逆时针排列。

    用你的图片:

    I = imread('Image.jpg');
    
    % --- Get a BW image, remove the title
    BW = rgb2gray(I)<200;
    BW(1:50,:) = 0;
    
    % With a logical image, simply use:
    % BW = double(Img);
    
    % --- Find the outer contour coordinates
    BW = imfill(BW, 'holes');
    C = imcontour(BW,1);
    
    % --- Arrange the contour counter-clockwise
    x = fliplr(C(1,2:end));
    y = fliplr(C(2,2:end));
    
    % --- Display    
    imshow(BW)
    hold on
    plot(x, y);
    
    % --- Display regularly spaced markers to check the order
    bin = linspace(1,numel(x), 11);
    bin = round(bin(1:end-1));
    cm = jet(numel(bin));
    for i = 1:numel(bin)
        scatter(x(bin(i)), y(bin(i)), 'o', 'MarkerEdgeColor', 'none', ...
            'MarkerFaceColor', cm(i,:));
        text(x(bin(i)), y(bin(i))+10, num2str(i), 'color', cm(i,:));
    end
    

    轮廓存储在xy 向量中。结果是:

    最好的,

    【讨论】:

    • 非常感谢您的解决方案。但是,如果我想从bin = linspace(1,numel(x), 11); 中选择点的坐标,这里给出 11 个点。如何获得这些点的坐标?使用fliplr时,我以顺时针方式获得积分,与您所说的完全相反。 % --- Arrange the contour counter-clockwise x = fliplr(C(1,2:end)); y = fliplr(C(2,2:end));
    • 轮廓坐标在xy中,bin部分仅用于可视化。而fliplr 只是翻转矢量,因此根据您的方向,您可能想要也可能不想使用它。如果您的矢量是垂直的,您可能需要使用flipud。清楚吗?
    • 知道了。谢谢。还有一件事,我使用的是源图像 I,它是二进制而不是 RGB。如何修改此代码以使用它?简单地删除这些步骤是行不通的。
    • 好的。请发布您的源图片或回答以下几个问题:您使用imread 吗?如果是这样,class(Img)max(Img(:)) 的输出是什么?
    • class(img) 的输出是合乎逻辑的 & max(Img(:)) : 1 lmage Link
    猜你喜欢
    • 2021-12-26
    • 2021-08-29
    • 1970-01-01
    • 2020-04-26
    • 2017-10-08
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多