I see that you want to mark and label all the edges in a polygon with different orientations and lengths.
You may refer to the steps mentioned below to do so:
1. Convert the input image to grayscale using the “rgb2gray” function. Next, use the grayscale image as input for an edge detector to prepare for the line detection process. This can be achieved using the “edge” function with the "canny" method, as illustrated in the code snippet below:
For more information on “rgb2gray” and “edge” function, you may refer to links of MathWorks documentation mentioned below:
2. Next, you can apply the Hough transform to detect edges of various orientations in the image using the “houghpeaks” function to identify possible lines. The output contains the orientations and locations of the detected lines. The code snippets illustrates this:
imshow(H, [], 'XData', T, 'YData', R, 'InitialMagnification', 'fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H, 8, 'threshold', ceil(0.5 * max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x, y, 's', 'color', 'white');
For any further information on “hough” and “houghpeaks” functions, refer to the related documentation links mentioned below:
3. Finally, you can use the “houghlines” function to extract lines from the detected peaks. Overlay the detected lines on the original image and visualize them. For each detected line, mark the start and end points with yellow and red crosses, respectively:
lines = houghlines(BW, T, R, P, 'FillGap', 5, 'MinLength', 1);
figure, imshow(I), hold on
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1), xy(:,2), 'LineWidth', 3);
plot(xy(1,1), xy(1,2), 'x', 'LineWidth', 2, 'Color', 'yellow');
plot(xy(2,1), xy(2,2), 'x', 'LineWidth', 2, 'Color', 'red');
len = norm(lines(k).point1 - lines(k).point2);
On following the above-mentioned steps, I got the output image as attached below:
I hope this helps!