how to fit ellipse to an image with cylinderical shape
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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
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;
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 件のコメント
Image Analyst
2020 年 4 月 6 日
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.
Hiro Yoshino
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:
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!