I want to get an image only with the grapes and the three circles (red, green, blue). [I need to remove all the smears]. how can I improve my code for that?
this is my code:
RGB = imread('img_3235.jpg');
GRAY = rgb2gray(RGB);
threshold = graythresh(GRAY);
originalImage = im2bw(GRAY, threshold);
originalImage = bwareaopen(originalImage,250);
imshow(originalImage);
CC = bwconncomp(originalImage); %Ibw is my binary image
stats = regionprops(CC,'pixellist');
this is my image (img_3235.jpg).
and this is the result of my code:
You can perform a morpholical closing using IMCLOSE
.
se = strel('disk', 10); %# structuring element
closeBW = imclose(originalImage,se);
figure, imshow(closeBW);
The closing of A by B is obtained by the dilation of A by B, followed by erosion of the resulting structure by B.
An alternative solution is to median filter with an appropriate window size, just after the threshold is applied:
...
originalImage = im2bw(GRAY, threshold);
originalImage = medfilt2(originalImage,[37 37],'symmetric');
originalImage = bwareaopen(originalImage,250);
figure, imshow(originalImage);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With