close all; clear all; clc;

imgpath = 'streched.png';

[vertices, ashape, edge, gray, bw] = detectVertices(imgpath);

figure; imshow(bw); hold on;
%plot(vertices(:,1), vertices(:,2), 'r.');

centers = clusterizeVertices(vertices,20);
plot(centers(:,1),centers(:,2),'gx');

[connectionMatrix distanceMatrix] = computeGraph(centers, 1);

[springLength, maxDeflectionAngle, maxDeflectionLocation, springDeflection, avgPitch, maxPitch, maxPitchLocation, pitchStdDeviation, midpointMatrix, edgeMidpointMatrix] = measureValues(bw, distanceMatrix, connectionMatrix, centers, 8);
plotResult(imgpath, springLength, maxDeflectionAngle, maxDeflectionLocation, springDeflection, avgPitch, maxPitch, maxPitchLocation, pitchStdDeviation, midpointMatrix, edgeMidpointMatrix, distanceMatrix, connectionMatrix, centers);