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

1 回表示 (過去 30 日間)
Sai Ongole
Sai Ongole 2019 年 7 月 8 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 14 日
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

採用された回答

Image Analyst
Image Analyst 2019 年 7 月 13 日
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?
  3 件のコメント
Image Analyst
Image Analyst 2019 年 7 月 14 日
Sai, those are not database functions. They are variables. "mask" is your "img_subt_binary" or your "BW2". Rows and columns are the number of rows and columns in your binary image mask:
[rows, columns] = size(BW2);
Can you do it now?
Image Analyst
Image Analyst 2019 年 7 月 14 日
Sai: OK I did it for you. See the red lines outlining the cone angle in the image below.
0000 Screenshot.png
This is a much better way than the way you originally posted since it takes ALL cross sections into account, not just one row or column.
All you need to complete is how to get the angle. You can compute the angle of the top line from the coefficients and of the bottom line from the other coefficients and then subtract them to get the delta angle. I'm sure you can do it. See attached script.

サインインしてコメントする。

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 13 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 13 日
Half Length of the cone area, lets say binary image is image_bw
[rows colm]=size(image_bw);
image_bw(1:round(rows/2),:)==0;
% Area in % with respect to Total Image
area_half_cone=(sum(image_bw)/(rows*colm))*100;
Here, used calculated the lower half of the cone
  4 件のコメント
Sai Ongole
Sai Ongole 2019 年 7 月 13 日
編集済み: Sai Ongole 2019 年 7 月 14 日
I need the area of the upper half of the cone. I tried
image_bw(round(rows/2):rows(end),:)==0;
It is giving me the same result as the one below gave me.
image_bw(1:round(rows/2),:)==0;
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 14 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 14 日
I need the area of the upper half of the cone...
image_bw(round(rows/2):end,:)==0;
Rest code is same, please do refer the answer of @ImageAnalyst too.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by