2

I need to apply a binarization process in some images. So far I've only tested three techniques of thresholding in OpenCV (Otsu, adaptive and fixed) and adaptive was what got better results but still not as good as expected. I would like to know from someone who works with image processing, some suggestions that I can do some tests. I did a search and found many ways, even many, so many that I do not know where to start. So, here I am asking for suggestions from those who understand the subject.

Example of the image: enter image description here

Mikhail
  • 20,685
  • 7
  • 70
  • 146
U23r
  • 1,653
  • 10
  • 28
  • 44
  • It depends on the environment. What kind of images are you trying to binarize? Could you post a sample image? – Daniel Martín Nov 19 '13 at 13:50
  • It's basically the image of numbers with a white font, on black/red background, like this https://drive.google.com/file/d/0BzUNc6BOkYrNNlE3U04wWEVvVE0/edit?usp=sharing (for an OCR tool) – U23r Nov 19 '13 at 14:02

5 Answers5

2

The following steps gave me the best result:

  1. Extract green/blue channel of image.\

    vector< Mat > channels(3);
    split(frame, channels);

  2. Apply gaussian blur.

    GaussianBlur(channels[0], channels[0], Size(7, 7), 0, 0);

  3. Apply thresholding with THRESH_OTSU flag.

    threshold(channels[0], channels[0], -1, 255, THRESH_BINARY+THRESH_OTSU);

Also see these posts on thresholding: Adaptive threshold of blurry image and Threshold of blurry image - part 2

Community
  • 1
  • 1
asif
  • 975
  • 8
  • 16
  • I did this but there is a problem with gaussianBlur and threshold functions. It said `>main.obj : error LNK2019: unresolved external symbol "double __cdecl cv::threshold(class cv::_InputArray const &,class cv::_OutputArray const &,double,double,int)" (?threshold@cv@@YANABV_InputArray@1@ABV_OutputArray@1@NNH@Z) referenced in function _main` – U23r Nov 26 '13 at 06:39
  • and `>main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_,double,double,int)" (?GaussianBlur@cv@@YAXABV_InputArray@1@ABV_OutputArray@1@V?$Size_@H@1@NNH@Z) referenced in function _main` ` What is it? – U23r Nov 26 '13 at 06:41
  • It seems that you are missing `imgproc` library. See [here](http://stackoverflow.com/a/10474630/2782865). – asif Nov 26 '13 at 10:12
1

I usually start with some simple thresholds:

1) average intensity

2) median intensity

3) average + k * standard deviation of intensity (start with k=1)

4) median + k * median absolute deviation

Only if simple thresholds are not working I am considering more complicate ones, like adaptive threshold.

Michael Burdinov
  • 4,348
  • 1
  • 17
  • 28
0

You could try

  1. edge detection followed by erosion to get rid of small edges get
  2. small neighborhoods around edge pixels and find thresholds for them
  3. threshold the original image based on those values

A simpler option is to perform meanshift filtering, using the brightest region as the starting segment.

Totoro
  • 3,398
  • 1
  • 24
  • 39
0

Positions of the numbers seems to be fixed, as well as their shapes and proportions of bounding rectangle. You can split your image to several regions and process them separately, waiting white numbers on black background or gray numbers on red background, or something similarly specific.

wl2776
  • 4,099
  • 4
  • 35
  • 77
-1

I would do this in these basic steps:

  • Convert colourful pixels to black. This will leave (hopefully) white letters on a black background.
  • Convert resulting image to grayscale.
  • Create a histogram of pixel intensity values for the grayscale image;
  • Approximate the first derivative of the ordered histogram data to find a large change in number of pixels found for a given pixel intensity value (hopefully corresponding to the letter values).
  • Use that value as the threshold.

These steps are only a brief description of where I would start. Reflection will be a difficult issue to solve I think (stuff I'm working on now has partial shadow which is a similar problem).

If this seems very involved, there's no substitute for a good image processing book and lots of programming practice.

Hope this helps!

William
  • 26
  • 5