MATLAB: (UPDATED) Need to find area of an image at half length

digital image processingimage analysisimage processingMATLAB and Simulink Student Suite

I have a binary image of a fuel spray. My goal is to find the cone angle of the spray. One of the research paper tells me to find the area of the spray at half length and use a formula from there. I'm struck at finding area area at half length of the spray.
The code below shows what I tried. I've also tried other methods such as trimming out all the non zero elements and just calculating the angle from the end of the spray. Since that is giving me an inaccurate answer, I'm here looking for help.
img_subt_binary= imbinarize(img_subt);
BW2= BiggestImageOnly(img_subt_binary);% Show the biggest image of the picture
figure(2),imshow(BW2),
title('Filtered Binary Image')
[pixelCount, grayLevels] = imhist(BW2);
% figure(3) % bar(grayLevels, pixelCount);
[the_length,the_width]=size(BW2)
%% Spray Angle
half_length=the_length/2;
for j=1:half_length
j=j+1;
[LL(j),WW(j)]= size(BW2);
final_width=max(WW);
end
angle= atan(final_width/half_length)
I'm expecting the angle to be around 20 degrees

Best Answer

Why not just find the right and left half edges and fit lines through them,
col1 = zeros(1, rows);
col2 = zeros(1, columns);
for row = 1 : rows
c = find(mask(row, :), 1, 'first');
if ~isempty(c)
col1(row) = c;
end
col2(row) = find(mask(row, :), 1, 'last');
end
col1(col1~=0) = []; % Remove where there were no white pixels.

col2(col2~=0) = []; % Remove where there were no white pixels.
x = 1 : length(col1);
leftCoeffs = polyfit(x, col1, 1);
rightCoeffs = polyfit(x, col2, 1);
(adapt as needed) and then use an appropriate trigonometry formula to find the angle between the two fitted lines?
Related Question