How to plot a weighted line through an origin point
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 3 Apr 2014
You don't want to include those rows. They don't have the plume in them so why should you include them?
0 Comments
See Also
Categories
Find more on Blue in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!