I have a bw image made up of lines, and am trying to extract "critical" points from it. That is, I am trying to extract an ordered list of points, such that connecting adjacent points should give something back that is close to the original input.
I first tried detecting corners using C = corner(I)
and variants. These detected good points, however were unordered, so didn' accomplish what i was looking for.
I have a piece of code currently that gives me the ordered list, however does not extract enough points to describe the image. Attached is the sample image, and code:
I = imbinarize(rgb2gray(imread('rightRaw.png'))); % Read image ad convert to binary
J = padarray(I, [1, 0], 1, 'post'); % Insert row of ones at the bottom
J = imfill(J, 'holes'); % Fill inner pixels.
J(end, :) = J(end, :) & J(end-1, :); % Keep only the closing line at the bottom
% Get X,Y coordinates of all white points
[Y, X] = find(J > 0);
% Get boundary of the set of points
k = boundary(X, Y);
% Get x,y coordinates of the boundary
x = X(k);
y = Y(k);
% Remove coordinated of bottom line
x = x(y < size(J, 1));
y = y(y < size(J, 1));
The result is as follows (line in white, points in blue)
As you can see, connecting adjacent points will not describe the image well at all. I believe the issue is that I am using boundary
. Is there a way to preserve information about all of the edges so that I get internal lines as well? There will be multiple shapes and lines possibly inside of them.
I essentially want the same points retrieved by corner
, however with ordering preserved.
Here is a copy of my original:
@beaker: