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);figureimshow(background)I2 = I - background;figureimshow(I2)figureI3 = imadjust(I2);imshow(I3);bw = imbinarize (I3);figureimshow(bw)bw1 = bwareaopen(bw, 50);figureimshow(bw1)cc = bwconncomp(bw1, 4)
Best Answer