1

I have an image (left image), but it has some discountinuties and noises in the edges. I want to use a method (filtering, image repairing, etc. ) that can give me the right image. Is there any method that can do this for me in Matlab?

Sam
  • 939
  • 5
  • 14
  • 41

1 Answers1

3

A series of dilation and erosion operations (called "closing") might suffice depending on your needs. You can combine the imdilate and imerode operations, performing them in sequence as imclose, or "manually" as in this example:

se=strel('ball',4,4); 
im_er = imdilate(im,se);
im_er = imerode(im_er,se);

The imdilate operation increases regions of high valued pixels, the second shrinks them. There are various shapes of object with which to perform the erosion/dilation, you might need to experiment or read up on which is most useful for your scenario.

In your particular case it looks like the RGB colorspace was ok for performing the morphological operations. I got the result (right frame) with your image (left frame) after rendering the red circles blue (middle frame), using the above operations (two dilations and one erosion):

enter image description here

Clearly this does not remove some of the unwanted features, but it seems to fix most of them. There are residual white pixels in some parts where the image was dilated, working with only one of the channels or in a different colorspace (for instance HSV) might be a workaround for that.

Finally, it also looks like you would want to limit the operations to the "regions of interest" (ROI) enclosed by the red circles, for that you should check other Q&A posts on SO, for instance here or here (search for "matlab roi").

edit

For the OPs new image applying the following morphing:

se=strel('ball',4,4); 
im_er = imdilate(im,se);
im_er = imdilate(im_er,se);
im_er = imerode(im_er,se);
se=strel('ball',3,3);
im_er = imerode(im_er,se);

results in this image:

enter image description here

Note: to get better results use the roi functions!

Community
  • 1
  • 1
Buck Thorn
  • 5,024
  • 2
  • 17
  • 27