How to count area under given surface ?

Hello,
I want to count areas limited by green lines.
So, for my image the result is three areas.
Can anyone help me please.

1 件のコメント

darova
darova 2020 年 4 月 30 日
do you have coordinates of green lines?

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

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 30 日
編集済み: Ameer Hamza 2020 年 4 月 30 日

0 投票

Try this. It gives the area of three regions in number of pixels
im = im2double(imread('area.jpeg'));
im(:,end-5:end,:) = 0; % remove the white line at right and bottom of image
im(end-5:end,:,:) = 0;
mask = (im(:,:,1)>0.75) & (im(:,:,2)>0.75) & (im(:,:,3)>0.75);
regions = bwconncomp(mask);
areas = cellfun(@(x) numel(x), regions.PixelIdxList);
required_areas = maxk(areas, 3);

4 件のコメント

MMSAAH
MMSAAH 2020 年 5 月 3 日
Thank you for your reply.
For this line :
required_areas = maxk(areas, 3);
Did you mean ? max(areas, 3);
However, when running the above code, I get more than three values for the required area:
required_areas =
3 3 3 118 116 3 106
Could you please let me know how to correct it ?
Ameer Hamza
Ameer Hamza 2020 年 5 月 3 日
No, I meant maxk(): https://www.mathworks.com/help/releases/R2020a/matlab/ref/maxk.html. Are you using MATLAB release older than R2017b?
MMSAAH
MMSAAH 2020 年 5 月 4 日
I'm using R2016a.
I've changed maxk() by :
[val ind] = sort(areas,'descend');
required_areas=val(1:3);
Now, it works.
Is it possible to transform the number of pixels to cm ?
Ameer Hamza
Ameer Hamza 2020 年 5 月 4 日
You will need to specify the pixel per cm to find out the area.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDisplay Image についてさらに検索

タグ

質問済み:

2020 年 4 月 30 日

コメント済み:

2020 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by