4

I'm currently using OpenCV for detecting blobs in a binary image. I'd like to erase small lines without changing the big objects.

Here's an example: The original image is

Original image

And I want to convert it into the following

Transformed image

"Opening" didn't work, because when applying it the edges of the triangle were cut off. Is there any other method for removing the lines, without losing information of the big triangle?

1 Answers1

4

Use Erosion to remove such a noise,

The code look like,

 Mat src;//load source
 Mat dst;//destination image
 Mat element = getStructuringElement(  MORPH_RECT,Size(5,5), Point( -1, -1 ) ); // kernel performing drode 
 erode( src, dst, element );

Edit

Adding @Bull comments here as it more appropriate method, which suggest erosion followed by dilation will get you very close to what you want.

enter image description here

Haris
  • 13,645
  • 12
  • 90
  • 121
  • "Erode" also reduces the size of the triangle, is there a way to remove the lines and retaining the original size of the triangle? – Bernhard Heinzelreiter Jul 21 '14 at 08:44
  • Check out [Morphology Transformations](http://docs.opencv.org/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html) – Haris Jul 21 '14 at 09:06
  • 2
    Yes, but erosion followed by dilation will get you very close to what you want. – Bull Jul 21 '14 at 09:11