I have a code below
clcclear allclose allI = imread('rice.png');imshow(I)background = imopen(I,strel('disk',15));I2 = I - background;imshow(I2)I3 = imadjust(I2);imshow(I3);level = graythresh(I3);bw = im2bw(I3,level);bw = bwareaopen(bw, 50);imshow(bw)cc = bwconncomp(bw, 4)grain = false(size(bw));grain(cc.PixelIdxList{50}) = true;grain(cc.PixelIdxList{30}) = true;grain(cc.PixelIdxList{80}) = true;grain(cc.PixelIdxList{75}) = true;grain(cc.PixelIdxList{70}) = true;imshow(grain);
now want to crop the grains shown in binary image from original image ,kindly help
Best Answer