Hi Surendra,
As per my understanding, you wish to calculate the angle of each extruded path with respect to the perpendicular and also calculate the length of the extruded path in ‘Original_Image.jpg’ image attached. Here I am assuming that you want to calculate the length in pixels and angle in degrees.
To calculate the angle and length of extruded part in the image, I have provided below with an example implementation that involves the following steps:
Step 1) Pre-processing step: Remove the parent boundary in original image
- Parent boundary in the image is the boundary having largest connected pixels.
- To delete the pixels on parent boundary, the boundary perimeter > 500 pixels are extracted, which is later subtracted from original image. This can be done using "imdilate" and "imerode" functions.
- Below is an example code snippet for pre-processing step. Here "binary_img" is the binary image of "Original_Image.jpg" image using "imbinarize" function.
boundaries = bwboundaries(binary_img);
stats = regionprops('table', bwlabel(binary_img), 'Perimeter');
binary_parent_boundary = binary_img;
boundary = boundaries{k};
if stats.Perimeter(k) > 500
mask = poly2mask(boundary(:,2), boundary(:,1), size(binary_img,1), size(binary_img,2));
mask_dilated = imdilate(mask, strel('disk', 15));
mask_eroded = imerode(mask_dilated, se);
binary_parent_boundary(mask_eroded) = 1;
binary_extruded = ~logical(binary_img - binary_parent_boundary);
The "binary_extruded' image is shown below. This image shows only extruded parts of the original image.
Step 2) Extract boundary information of each extruded part:
- The boundary properties of each extruded part can be calculated using "regionprops" function with "Perimeter" and "Orientation" property enabled.
- Here the length of extruded part is considered to be half of its perimeter.
- Use similar approach as showed in Step 1) to extract the boundary information from "binary_extruded" image.
- For each extruded part, angle and length can be extracted using the following code:
angle = (90 - stats.Orientation(k));
length = stats.Perimeter(k)/2;
Below image shows the output, with angle and the length of each extruded part displayed on the image.
Please refer to below MathWorks Documentation for more information about the functions used:
I hope this help!