0

I would like to draw lines on the images manually (to be precise, labeling edges on the image manually), and output the corresponding edge map (binary image). I use MATLAB R2018a with the function imfreehand. But the edge map is rather discrete.

Here is my Matlab script.

% 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);

Top panel figure: I manually draw a diagonal line on img

Bottom panel figure: it is edgeMap and the labeled points (white) are rather discrete.

Question: Are there any methods to tackle this issue such that the labeled edges are continuous?

test.jpg. The blue line is draw manually edge map (binary image)

Community
  • 1
  • 1
K_inverse
  • 357
  • 3
  • 16

1 Answers1

1

Your line is just a linear interpolation of the points that you are given. To get the "continuous" version use interp1.

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

Alternatively, you can get all the coordinates by using

yy = interp1(x,y,min(x):max(x));
Nicky Mattsson
  • 3,052
  • 12
  • 28