I want to extract only the grapes from the images. Unfortunately, sometimes I don't get the grapes exactly.
I have a code that doesn't work well in all cases. Sometimes, it does not differentiate between the shadows and the grapes.
The example input image:

The result I'm getting:

And this is my code:
RGB = imread('DSC02807.JPG');
GRAY = rgb2gray(RGB);
threshold = graythresh(GRAY);
originalImage = im2bw(GRAY, threshold);
originalImage = bwareaopen(originalImage,250);
SE = strel('disk',10);
IM2 = imclose(originalImage,SE);
originalImage = IM2;
imshow(originalImage);
