【问题标题】:Label image edges is not continuous (Matlab) [duplicate]标签图像边缘不连续(Matlab)[重复]
【发布时间】:2018-07-31 08:28:24
【问题描述】:

我想在图像上手动画线(准确的说是手动在图像上标注边缘),并输出对应的边缘图(二值图像)。我将 MATLAB R2018a 与函数 imfreehand 一起使用。但边缘图相当离散。

这是我的 Matlab 脚本。

% Read the image
img = imread('test.jpg');
img_size = size(img);
height = img_size(1);
width = img_size(2);

% Draw a line on the image manually
figure(1);
im(img);
h = imfreehand(gca, 'Closed', false);

% Get positions (x, y) 
pos = h.getPosition();
x = int16( pos(:, 1) );
y = int16( pos(:, 2) );

% Create a binary image containing
% labeled edges
edgeMap = zeros(height, width);
for i = 1 : length(x)
    edgeMap( y(i), x(i) ) = 1;
end

% Show the edgeMap
figure(2);
im(edgeMap);

顶面板图:我在img上手动画了一条对角线

底部面板图:它是edgeMap,标记点(白色)相当离散。

问题: 有什么方法可以解决这个问题,使得标记的边缘是连续的?

【问题讨论】:

    标签: image matlab computer-vision


    【解决方案1】:

    您的线只是给定点的线性插值。要获得“连续”版本,请使用interp1

    line = @(x1) interp1(x,y,x1);
    

    或者,您可以使用获取所有坐标

    yy = interp1(x,y,min(x):max(x));
    

    【讨论】:

    • 谢谢。我还需要确保 (x, y) 是唯一的对并且是单一类型。
    猜你喜欢
    • 2014-09-18
    • 2017-06-17
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    相关资源
    最近更新 更多