Identify the extruded portion from object at different angle ??

1 view (last 30 days)
I attached origin and modified images. In original images, there are extruded part from its parent boundary at different location. How can I find the angle between a vertical line (which is shown in image modified in white colour) and line AC,AD,AE, so on...(which is shown in the image modified image, In modified image shown some of the angle which are in red,yellow and green colour and extruded part in blue colour). I want to a angle where the extruded portion are (angle BAC, BAD, BAE, so on..) and length of the extruded part (which is the length of the blue colour line).
Thank You

Answers (1)

Aishwarya
Aishwarya on 27 Oct 2023
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.
% Extract the boundaries from Original image
boundaries = bwboundaries(binary_img);
% Calculate the length of each boundary in Original Image
stats = regionprops('table', bwlabel(binary_img), 'Perimeter');
% Extract the parent boundary into another binary image.
binary_parent_boundary = binary_img;
for k = 1:height(stats)
boundary = boundaries{k};
% When boundary length is more than 500 pixels it represents parent boundary (adjusted as required)
if stats.Perimeter(k) > 500
% Create a binary mask from the boundary coordinates
mask = poly2mask(boundary(:,2), boundary(:,1), size(binary_img,1), size(binary_img,2));
% Mask is then dilated and eroded using a disk-shaped structuring element.
mask_dilated = imdilate(mask, strel('disk', 15));
mask_eroded = imerode(mask_dilated, se);
% Pixels that correspond to parts other than parent boundary is set to background
binary_parent_boundary(mask_eroded) = 1;
end
end
% Substract the parent boundary from the binary image to get only extruded parts
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 of each extruded part
angle = (90 - stats.Orientation(k));
% Length of each extruded part (Assuming half the perimeter of boundary)
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!
  3 Comments
Aishwarya
Aishwarya on 3 Nov 2023
Hi,
I would suggest to explore the different "properties" of "regionprops" function to get the width of the extruded part. Do look into the property "Extrema", "MinorAxisLength", from which an approximate of width can be extracted.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!