finding the centre line of the binary image

3 Ansichten (letzte 30 Tage)
Lord Thabet
Lord Thabet am 20 Sep. 2021
Kommentiert: Lord Thabet am 20 Sep. 2021
Hi,
I have been trying to find the mid points of the white pixel in binary image so that I can draw a horizontal centre line.
As shown in the below image.So I'm thinking that I can find the right and left side points and then from there I can find the middle point for each row and this will create a multiple points which will alow me to dwar a centre line.
please if any one would be happy to help me that would be great. Thanks in advance
This is the image that I have.

Akzeptierte Antwort

Image Analyst
Image Analyst am 20 Sep. 2021
Try
[rows, columns] = size(binaryImage);
leftEdges = nan(rows, 1);
rightEdges = nan(rows, 1);
for row = 1 : rows
t = find(binaryImage(row, :), 1, 'first');
if ~isempty(t)
leftEdges(row) = t;
rightEdges(row) = find(binaryImage(row, :), 1, 'last')
end
end
midPoints = (leftEdges + rightEdges) / 2;;
  5 Kommentare
Image Analyst
Image Analyst am 20 Sep. 2021
Bearbeitet: Image Analyst am 20 Sep. 2021
Looks like x and y are flipped. Try
x = 1:rows
plot(x, midPoints, '*')
Lord Thabet
Lord Thabet am 20 Sep. 2021
Thank you so much that did help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by