Curve Extraction from Binary Image

4 ビュー (過去 30 日間)
Zachariah Harris
Zachariah Harris 2020 年 11 月 24 日
回答済み: Amrtanshu Raj 2021 年 2 月 4 日
Hi Mathworks community. I have a black and white image and I am trying to extract the polynomial equation of the third line from the left in the image shown below. I am having trouble extracting the locations of the non-zero pixels and then determining the polynomial coefficients (fitting the line). My code is below.
% Label image with 1,2,3,4 for each connected component
L = bwlabeln(BW3);
% return the row and column locations of label #3 within the image
[row,col]=find(L(:,:) == 3);
% Extract the polynomial coeffecients of each line in the image
n=2;
p = polyfit(col,row,n)
% Show the original black and white image and hold on axis
imshow(BW3)
hold on
% Plot the determined polynomial line as a red line on the same figure
x=0:.1:500;
plot(polyval(p,x),x,'r')

回答 (1 件)

Amrtanshu Raj
Amrtanshu Raj 2021 年 2 月 4 日
Hi,
In the image there are only 2 labels generated by bwlabeln,
Assuming that you wish to generate a polynomial and plot it for the curve in middle (which is label 2 in L) of the image, I have made edits to your code so that it generates the required plot.
The major error was in the line
p = polyfit(col,row,n)
Code -
% Label image with 1,2,3,4 for each connected component
L = bwlabeln(BW3);
% return the row and column locations of label #3 within the image
[row,col]=find(L == 2)
% Extract the polynomial coeffecients of each line in the image
n=2;
p = polyfit(row,col,n);
% Show the original black and white image and hold on axis
imshow(BW3)
hold on
% Plot the determined polynomial line as a red line on the same figure
x=0:.1:500;
plot(polyval(p,x),x,'r')
Hope this help !!

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by