Separation of rice grains . I want to separate out the grains that are darker in the image.
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
DGM
on 24 Feb 2022
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!