0

I have image as following (so, this is white figure on red background. This figure have two thin red lines inside it)

in_image

and I want to receive following image (remove red background but not two red lines inside figure)

enter image description here

I was trying convexHull from OpenCV, but, obviously that approach works only on convex figures. My feeling that convolution may help here, but have no real idea yet.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Arsen
  • 153
  • 1
  • 12

3 Answers3

1

Dilate and Erode should work for your example:

Mat image = imread("image1.jpg");   

int erosion_size = 5;
int dilation_size = 6;

int threshold_value = 200;

Mat mask;
cvtColor( image, mask, CV_BGR2GRAY );

//BINARY THRESHOLDING
threshold( mask, mask, threshold_value, 255, 0);

Mat erosion_element = getStructuringElement(MORPH_RECT, Size( 2*erosion_size + 1, 2*erosion_size+1 ), Point( erosion_size, erosion_size ) );

Mat dilation_element = getStructuringElement(MORPH_RECT, Size( 2*dilation_size + 1, 2*dilation_size+1 ), Point( dilation_size, dilation_size ) );

dilate(mask, mask, erosion_element);
erode(mask, mask, dilation_element);

Mat target;
image.copyTo(target, mask);

imshow("hello",target);

waitKey();

OutPut:

ouput example

ivan_a
  • 613
  • 5
  • 12
0

suggestions: :)

berak
  • 39,159
  • 9
  • 91
  • 89
  • berak, flood fill by black color from (0,0) point will flood also red lines by black :) Notice, those red lines not separated by any pixel from background on left side of figure. – Arsen Sep 07 '13 at 13:33
  • ah ok. sorry. got it totally backwards. should i just delete it ? – berak Sep 07 '13 at 14:03
  • np, you can leave it for history :) anyway, thanks for your time! – Arsen Sep 07 '13 at 14:16
0

he-he, it looks like convolution with circle having diameter slightly bigger (8 pixels, for example) than line thickness works! so, algorithm will looks as following:

  1. convolve with circle having diameter slightly bigger than line thickness
  2. normalize convolution, you are interested in values greater than 0.95-0.97
  3. for each point on convolution function (with values greater than 0.95-0.97) you should zero all neighborhoods which are in range R=diameter/2
Arsen
  • 153
  • 1
  • 12