Clear Filters
Clear Filters

Detecting blob with straight or round ends

7 views (last 30 days)
Hi everyone,
As you can see I have an image here of objects with different shapes. Each object has either a round or straight/flat ends. The objects are classified such that if they have both rounded ends they are called a cigar, if both are straight it's a square rod and if half is round it's a half-cigar. I was wondering if there is an easy way around to detect the straight or round ends of the object? It will be great to receive some inputs from the MATLAB community.

Answers (1)

Image Analyst
Image Analyst on 13 Jan 2023
Try bwferet to get the endpoints of the cigars. Then take a certain number of point around the endpoint and fit it to a circle using the attached function. Compute the distance of the training set to the fitted circle to get the average deviation from a circular shape. See how much that number varies for each shape of end. Circular ends will have a low deviation while non-circular ends will have a higher number.
Image Analyst
Image Analyst on 13 Jan 2023
Sounds reasonable as long as all points are from the same blob, which should be the case if the blobs are well separated. If not, you'd want to label the image first with bwlabel.
Muhammad Syahmeer
Muhammad Syahmeer on 13 Jan 2023
Thank you so much for that @Image Analyst. I think I'm almost done but wanted to run a final check if that's okay. I added these final codes to find the average deviation from the fitted circle. Guess the next step for me is to determine a threshold that decides one is rounded or the other.
%% Find coordinates of 20 nearest point to one of the end point
[minValues, idx] = mink(distancesP,20);
%Fit a circle
[xc,yc,R,a] = circfit(closest_x,closest_y);
%Calculate coordinates of fitted circle (half pi since it's half circle)
th = linspace(0,pi,20)';
xe = R*cos(th)+xc; ye = R*sin(th)+yc;
%calculate average deviation
distancesP = sqrt((closest_x- xe).^2 + (closest_y- ye) .^ 2);

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!