3

Hi I'm attempting to filter an image with 4 objects inside using MatLab. My first image had a black background with white objects so it was clear to me to filter each image out by finding these large white sections using BW Label and separating them from the image.

The next image has noise in it though. Now I have an image with white lines running through my objects and they are actually connected to each other now. How could I filter out these lines in MatLab? What about Salt and pepper noise? Are there MatLab functions that can do this?

user1701856
  • 71
  • 1
  • 7

2 Answers2

3

Filtering noise can be done in several ways. A typical noise filtering procedure will be something like threshold>median filtering>blurring>threshold. However, information regarding the type of noise can be very important for proper noise filtration. For examples, since you have lines in your image you can try to use a Hough transform to detect them and take them out of the play (or houghlines). Another approach can be to implement RANSAC. For salt & pepper type of noise, one should use medfilt2 with a proper window size that captures the noise characteristics (for example 3x3 window will deal well with noise fluctuations that are 1 pixel big...).

bla
  • 25,846
  • 10
  • 70
  • 101
1

If you can live with distorting the objects a bit, you can use a closing (morphological) filter with a bit of contrast stretching. You'll need the image processing toolbox, but here's the general idea.

  • Blur to kill the lines otherwise the closing filter will erase your objects. You can use fspecial to create a Gaussian filter and imfilter to apply it
  • Apply the closing filter to the image using imclose with a mask that's bigger then your noise, but smaller then the object pieces (I used a 3x3 diamond in my example).
  • Threshold your image using im2bw so that every pixel gets turned to pure black or pure white based

I've attached an example I had to do for a school project. In my case, the background was white and objects black and I stretched between the erosion and dilation. You can't really see the gray after the erosion, but it was there (hence the necessity for thresholding).

You can of course directly do the closing (erosion followed by dilation) and then threshold. Notice how this filtering distorts the objects.

FYI usually salt-and-pepper noise is cleaned up with a moving average filter, but that will leave the image grayscale. For my project, I needed a pure black and white (for BW Label) and the morphological filters worked great to completely obliterate the noise.

Morphological Filtering Example

tazer84
  • 1,743
  • 12
  • 11