필터 지우기
필터 지우기

Fitting lines and polynomialon on edge after edge extraction and finding a certain distance

조회 수: 3 (최근 30일)
I got the following edge after extracting it from a image which has been provided by me in attachmnent. I need to fit a red line along the lower edge and green horizontal line as shown in 2nd figure and find the distance.
What approach should I use???
The desired result I seek??
  댓글 수: 1
Matt J
Matt J 2020년 7월 25일
I have attached the matlab code for extracting the edge.
It would be more convenient for us if you simply attach a .mat file containing h.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 7월 25일
편집: Image Analyst 2020년 7월 25일
Really easy. Call bwconvhull(bw, 'union'). Then scan column-by-column using find() to get the last/lowest white point. Then fit those bottom rows to a quadratic with polyfit(), if you want - it's optional because the curve is not really needed to find the height of the last column. Then you simple need to find the last column where there is some white and subtract it from the max value. Something like (untested)
mask = bwconvhull(mask, 'union');
[rows, columns] = size(mask);
bottomRows = zeros(1, columns);
for col = 1 : columns
thisCol = mask(:, col);
r = find(thisCol, 1, 'last');
if ~isempty(r)
bottomRows(col) = r;
end
end
lastColumn = find(bottomRows > 0, 1, 'last');
bottomLine = max(bottomRows);
yline(bottomLine, 'Color', 'g', 'LineWidth', 2)
distance = bottomLine - bottomRows(lastColumn)
% Optional fitting
goodIndexes = bottomRows > 0;
c = 1:columns;
x = c(goodIndexes);
y = bottomRows(goodIndexes);
coefficients = polyfit(x, y, 2);
xFit = c;
yFit = polyval(coefficients, xFit);
hold on;
plot(xFit, yFit, 'r-', 'LineWidth', 2)
yLast = yFit(lastColumn);
plot(lastColumn, yLast, 'r+', 'MarkerSize', 30)
fittedDistance = bottomLine - yLast
% Will be different than other distance because the other one was actual
% and this one is from the regression.
  댓글 수: 3
Matt J
Matt J 2020년 7월 25일
편집: Matt J 2020년 7월 25일
A simpler way to generate bottomRows:
mask = ~cummax(bwconvhull(mask, 'union'),1,'reverse');
[~,bottomRows]=max(mask,[],1);
bottomRows=bottomRows-1;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by