Separation of rice grains . I want to separate out the grains that are darker in the image.

3 次查看(过去 30 天)
The image contains rice grains. I want to separate out the darker rice grains in image 'Main'. I have marked the ones which needed to be separate out in attachment 'Result'. I also want to count the no. of lighter and darker grians. I know the image has a lot of noise because i captured the grains by keeping them on laptop screen. Apologies for that.

回答(1 个)

DGM
DGM 2022-2-24
Segmentation might be a bit easier with a bit of a diffuser to deal with the bg. The median filter (or just downscaling the image) helps deal with it in this case.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/905805/Main.jpg');
A = rgb2gray(A);
A = medfilt2(A,[10 10]);
mask = imclearborder(A<150);
mask = bwareaopen(mask,2000);
imshow(mask)
S = regionprops(mask,A,'meanintensity','centroid');
C = vertcat(S.Centroid);
graincolor = vertcat(S.MeanIntensity);
grainmask = graincolor<60;
figure
imshow(A); hold on
for b = 1:numel(S)
if grainmask(b)
plot(C(b,1),C(b,2),'bo','markersize',25);
else
plot(C(b,1),C(b,2),'ro','markersize',25);
end
end

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by