MATLAB Answers

how to fit ellipse to an image with cylinderical shape

14 ビュー (過去 30 日間)
Malik Malik
Malik Malik 2020 年 3 月 30 日
編集済み: Malik Malik 2020 年 4 月 8 日
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?
  1 件のコメント
Adam Danz
Adam Danz 2020 年 3 月 31 日
If you share the code that inputs original_image and produces edge_image, I might be able to play around with it later.


回答 (2 件)

Image Analyst
Image Analyst 2020 年 3 月 31 日
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;
% 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 件のコメント
Malik Malik
Malik Malik 2020 年 4 月 7 日
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?


Hiro 2020 年 3 月 30 日
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 件のコメント
Malik Malik
Malik Malik 2020 年 3 月 31 日
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.


Community Treasure Hunt

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

Start Hunting!

Translated by