How to plot a weighted line through an origin point
3 次查看(过去 30 天)
显示 更早的评论
Hi all, so i am trying to plot lines as shown in the image below but with them both going through an origin point at the top centre of the figure where the injection nozzle would be. The code below shows the scanning for first and last white pixels(the image below is a negative, to give a more realistic view) and then an attempted weighting process to fit the lines to the origin, however , this hasn't worked. I think the problem lies where no white pixels were found at the top and therefore these rows haven't been taken into consideration.My reasoning for this is that size(leftColumns) and size(X) is 260, whilst BW_Length is 299. So maybe the solution comes from somehow including these rows, which i unfortunately don't know how to do. But i may well be wrong. Does anyone have any ideas? Thank you!
BW_Length=size(BW, 1);
next_row=1;
for row = 1:BW_Length
row_index=find(BW(row, :)>0, 1,'first');
if ~isempty(row_index)
leftColumns(next_row)=row_index;
rightColumns(next_row)=find(BW(row, :)>0, 1,'last');
X(next_row)=row;
next_row=next_row+1;
end
end
w=1-(X/BW_Length);
ab1=wpolyfit(X,leftColumns,1,w);
ab2=wpolyfit(X,rightColumns,1,w);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160068/image.png)
0 个评论
回答(1 个)
Image Analyst
2014-4-3
You don't want to include those rows. They don't have the plume in them so why should you include them?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!