# Detecting blob with straight or round ends

1 view (last 30 days)
Muhammad Syahmeer on 13 Jan 2023
Commented: Muhammad Syahmeer on 13 Jan 2023
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.
Cheers, How

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.
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);
closest_y=rows(idx);
closest_x=columns(idx);
%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);
average_P=mean(distancesP)

### Categories

Find more on Computer Vision With Simulink in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!