I have an RGB image with various signs. My main goal is to count the signs that are in contact with the image borders.
Approach and problem
I started by loading the image [Fig. 1], then converted it to grayscale and applied a median filter to get rid of some noise [Fig. 2]. Then I binarized it with a threshold of 0.2, which resulted in Figure 3. At this time I got my binarized image, but the problem is that some parts that belong to the same sign are appearing in various regions, instead of only one. Now my goal is to merge the regions that belong to the same object , so then I could use bwlabel to count how many signs are in the image, and use imclearborder to get rid of the ones in the border, and use bwlabel again to get the difference between the two.
My approach was to use bwmorph, Dilate to dilate the objects and then try to fill them with imfill, holes. But the problem is that if I dilate them in a small amount[Fig. 4], the imfill doesn't seem to fill them, if I dilate them by a big amount[Fig 5] all the objects start to merge :(
Code
img=im2double(imread('image.png')); figure, imshow(img)
img_gray=rgb2gray(img); imshow(img_gray);
img_mediana=medfilt2(img_gray, [3 3]); figure, imshow(img_mediana);
img_bin=im2bw(img_mediana, 0.2); imshow(img_bin)
img_dilate=bwmorph(img_bin, 'Dilate', 10); imshow(img_dilate)
img_fill=imfill(img_dilate, 'Holes'); figure, imshow(img_fill)
Figures
Fig 1:
Fig 1 http://dl.dropbox.com/u/5272012/1.png
Fig 2:
fig 2 http://dl.dropbox.com/u/5272012/2.png
Fig 3:
fig 3 http://dl.dropbox.com/u/5272012/3.png
Fig 4:
fig 4 http://dl.dropbox.com/u/5272012/4.png
Fig 5:
