
%% USAGE - detectVertices(pathname of image to be manipulated)
%
% Example:
%         [vertices, ashape, edge, gray, bw] = detectVertices('Spring01.png');


function [vertices, ashape, edge, gray, bw] = detectVertices(path)

image = imread(path);

gray = rgb2gray(image);
bw = im2bw(gray, 0.75);

edge = fourNeighbourEdge(bw);

% row and col of edge image
[row, col] = find(edge);
ashape = alphaShape(col, row, 170);  % 170 is the alpha radius - must be large enough to detect all spring segments
[~, vertices] = boundaryFacets(ashape);

% visualization of alpha shape vertices (left here as a comment for reference only)
%figure; plot(vertices(:, 1), vertices(:, 2), 'r*'); axis equal;

end