Counting Whole Grains of Rice

15 ビュー (過去 30 日間)
Joshua Bucher
Joshua Bucher 2020 年 10 月 14 日
編集済み: Matt J 2020 年 10 月 14 日
I have been tasked by my professor to count the number of rice in this picture (excluding the rice that make up the border of the image). Essentially we want the whole rice grains to count and not the partial ones at the border of this image.
I have a script that can count all of the rice. But I don't know how I can exclude the rice that are bordering the image.
How should I go about doing this?
I = imread('rice.png');
imshow(I)
imwrite(I,'rice.png');
SD=strel('disk',15);
background = imopen(I,SD);
figure
imshow(background)
I2 = I - background;
figure
imshow(I2)
figure
I3 = imadjust(I2);
imshow(I3);
bw = imbinarize (I3);
figure
imshow(bw)
bw1 = bwareaopen(bw, 50);
figure
imshow(bw1)
cc = bwconncomp(bw1, 4)

採用された回答

Matt J
Matt J 2020 年 10 月 14 日
編集済み: Matt J 2020 年 10 月 14 日
Go through the list of pixel coordinates in each grain and check if any of them are border pixels.
rice_grains=regionprops(bw1,'PixelList')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by