3

I'm try to improve my image quality by applying following shareholding to input image.

        CvSize sz = cvSize(img.width(), img.height());
        IplImage gry = cvCreateImage(sz, img.depth(), 1);
        cvCvtColor(img, gry, CV_BGR2GRAY);
        cvAdaptiveThreshold(gry, gry, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 5, 4);

This is my input file

enter image description here

by applying threshold I need to draw all the lines in white and all other areas in black but in my out put there are some missing lines. So please can some one explain how to overcome with this problem ?

This is my out put after applying above threshold.

enter image description here

LkDev
  • 221
  • 3
  • 9

2 Answers2

2

you should do erosion (cvErode() in opencv) and then dilate (cvDilate()) to get rid of the small speckles. Hope this helps

mkuse
  • 2,250
  • 4
  • 32
  • 61
  • Thank you very much for your reply.Yes its true it can use to remove those speckles, But how can I connect those disconnected lines ? That is the main problem that I have here. – LkDev Oct 22 '12 at 13:02
  • I think you should iterate blob by blob (connected component analysis) and dilate until number of components become one. please have a look at connected components labelling on wikipedia if you are not aware of it. OpenCV and Matlab have inbuilt functions for CCA – mkuse Oct 23 '12 at 12:05
1

I hope you've already found the answer, if not.... Try some gaussian blur before you threshold:

Mat image = imread("mX5h6.jpg", IMREAD_GRAYSCALE);
GaussianBlur(image, image, Size(3, 3), 0, 0);
adaptiveThreshold(image, image, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 5, 4);
imshow("image", image);
tofi9
  • 5,775
  • 4
  • 29
  • 50