how to fit ellipse to an image with cylinderical shape

6 views (last 30 days)
Hi
I have to fit an ellipse to an image with a cylinder(see the attached image). after using the edge detection, i could recognize the ellipse shape but i couldn't find a way how to fit an ellipse on to it, or in other words i couldn't extract that part from rest of the image.
any suggestions?
Thanks!
  1 Comment
Adam Danz
Adam Danz on 31 Mar 2020
If you share the code that inputs original_image and produces edge_image, I might be able to play around with it later.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 31 Mar 2020
First of all, don't do an edge detection. I don't know why people always think edge detection is the first step in any image processing algorithm. In your case it's definitely NOT. You should do a simple threshold, then scan the image to find the right edge, then get the semi axes from the values. Assuming it's perfectly aligned, try something like (untested)
mask = imbinarize(grayImage);
[rows, columns, numColors] = size(grayImage);
rightColumns = zeros(rows, 1);
for row = 1 : rows
thisRow = mask(row, :);
t = find(thisRow, 1, 'last');
if ~isempty(t)
rightColumns(row) = t;
end
end
% Then get rid of any outliers that you may get if you're not perfectly aligned (for you to do).
% Find top and bottom (first and last elements of right rightColumns).
topRow = find(rightColumns, 1, 'first')
bottomRow = find(rightColumns, 1, 'last')
% Get ellipse semi-axes, a and b
b = (bottomRow - topRow) / 2
nonZeroIndexes = rightColumns > 0;
xCenter = min(rightColumns(nonZeroIndexes)
yCenter = mean([topRow, bottomRow])
a = max(rightColumns(nonZeroIndexes)) - min(rightColumns(nonZeroIndexes))
% Now you have the equation of an ellipse: ((x-xCenter)/a)^2 + ((y-yCenter)/b)^2 = 1
  7 Comments
Image Analyst
Image Analyst on 6 Apr 2020
That's a different t. That t is the angle. And they're the wrong equations. I think they should be
t = linspace(0, 360, 500);
x = xCenter + a * cosd(t);
y = yCenter + b * sind(t);
Try that. I've got a meeting with the Mathworks over the next two hours. If it doesn't work, let me know and I'll look at it after my Mathworks board meeting.
Malik Malik
Malik Malik on 7 Apr 2020
Edited: Malik Malik on 8 Apr 2020
It does generate the ellipse but its bigger and not fit over the ellipitical part of the image. See the attached results.
Thanks for the help. any suggestions?

Sign in to comment.


Hiro Yoshino
Hiro Yoshino on 30 Mar 2020
I am not an expert - please see the following page and hopefully there are some similar examples for you.
If you are fancy to app, the try this out:
  1 Comment
Malik Malik
Malik Malik on 31 Mar 2020
I don't want to select the points by myself. i want to do is that after edge detection ellipitical shape detected seperated from rest of the image as ellipse.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!