How to draw a boundary line for spray image

조회 수: 8 (최근 30일)
Rohit Thokala
Rohit Thokala 2022년 1월 13일
댓글: Image Analyst 2022년 1월 14일
I want to draw inclined line on a binary image that seperates the image in percentage of white pixels as shown in the figure. End points of the line can be arbitary and the line should look like a tangent to the spray cloud. Thanks in advance.
  댓글 수: 2
Bjorn Gustavsson
Bjorn Gustavsson 2022년 1월 13일
Considering that the 2 regions in your image aren't separated by a line but rather some curve (or a polyline with a break-point about half-way up) this will not work as well as you should do. Perhaps you should aim to find the best circle (ellipse?) that does the job?
Adam Danz
Adam Danz 2022년 1월 13일
편집: Adam Danz 2022년 1월 13일
If you know what section of the image should define the divider line such as the upper half of this image, then you could fit a line to that boundary, ignoring the bottom half. Then, once you know the slope of the line, you could incrementally move it from left to right, computing the percentage of white pixels on each iteration, until you reach 5%+/-threshold.

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

채택된 답변

Image Analyst
Image Analyst 2022년 1월 13일
Scan down the image to get the left edge
mask = bwareafilt(mask, 1); % Get largest blob only (if you want that).
[rows, columns] = size(mask);
leftEdge = zeros(rows, 1);
for row = 1 : rows
t = find(mask(row, :), 1, 'first');
if ~isempty(t)
leftEdge(row) = t;
end
end
% Extract only rows that had a white pixel in them.
r = 1 : rows;
validLines = leftEdge ~= 0;
r = r(validLines);
leftEdge = leftEdge(validLines);
Then you might try a piecewise linear fit, like my attached demo to split the left edge up into two linear portions.
  댓글 수: 4
Rohit Thokala
Rohit Thokala 2022년 1월 14일
편집: Rohit Thokala 2022년 1월 14일
Yes sir (@Image Analyst) I understand what you have mentioned in the above code, I am trying to create a linear fit from the best possible data. If I remove these zero values from the data, what about the column values that are associated with them. Is there a way to remove column values associated with zero white cell rows?
Image Analyst
Image Analyst 2022년 1월 14일
Please try it. I don't think you are or you'd realize that when I do
r = r(validLines);
leftEdge = leftEdge(validLines);
I'm extracting only the "good" edge locations from both the r and y arrays. Note that if you want to try to fit a line to it, r is the x and leftEdge is the y, contrary to what you're probably thinking.
but you can't just fit the whole thing to a line
coefficients = polyfit(r, leftEdge, 1);
because the bottom part is not a good line and certainly not the same slope as the upper part. That's why you have to use a piecewise linear fit like I did in the example I attached.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by