Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove noise from a binary image

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). enter image description here

and this is the result of my code: enter image description here

like image 953
Alon Shmiel Avatar asked Oct 10 '12 13:10

Alon Shmiel


2 Answers

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.

Result

like image 68
Yamaneko Avatar answered Nov 12 '22 04:11

Yamaneko


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);

enter image description here

like image 39
bla Avatar answered Nov 12 '22 03:11

bla