Threshold of blurry image - part 2

前端 未结 6 1714
死守一世寂寞
死守一世寂寞 2021-02-03 11:40

How can I threshold this blurry image to make the digits as clear as possible?

In a previous post, I tried adaptively thresholding a blurry image (left)

相关标签:
6条回答
  • 2021-02-03 11:48

    Some hints that you might try out:

    • Apply the morphological opening in your original thresholded image (the one which is noisy at the right of the first picture). You should get rid of most of the background noise and be able to reconnect the digits.

    • Use a different preprocessing of your original image instead of morpho closing, such as median filter (tends to blur the edges) or bilateral filtering which will preserve better the edges but is slower to compute.

    • As far as threshold is concerned, you can use CV_OTSU flag in the cv::threshold to determine an optimal value for a global threshold. Local thresholding might still be better, but should work better with the bilateral or median filter

    0 讨论(0)
  • 2021-02-03 11:49

    If you're willing to spend some cycles on it there are de-blurring techniques that could be used to sharpen up the picture prior to processing. Nothing in OpenCV yet but if this is a make-or-break kind of thing you could add it.

    There's a bunch of literature on the subject: http://www.cse.cuhk.edu.hk/~leojia/projects/motion_deblurring/index.html http://www.google.com/search?q=motion+deblurring

    And some chatter on the OpenCV mailing list: http://tech.groups.yahoo.com/group/OpenCV/message/20938

    The weird "halo effect" that you're seeing is likely due to OpenCV assuming black for the color when the adaptive threshold is at/near the edge of the image and the window that it's using "hangs over" the edge into non-image territory. There are ways to correct for this, most likely you would make an temporary image that's at least two full block-sizes taller and wider than the image from the camera. Then copy the camera image into the middle of it. Then set the surrounding "blank" portion of the temp image to be the average color of the image from the camera. Now when you perform the adaptive threshold the data at/near the edges will be much closer to accurate. It won't be perfect since its not a real picture but it will yield better results than the black that OpenCV is assuming is there.

    0 讨论(0)
  • 2021-02-03 11:53

    I've tried thresholding each 3x3 box separately, using Otsu's algorithm (CV_OTSU - thanks remi!) to determine an optimal threshold value for each box. This works a bit better than thresholding the entire image, and is probably a bit more robust.

    enter image description here

    Better solutions are welcome, though.

    0 讨论(0)
  • 2021-02-03 12:05

    Another option is to use region growing techniques. We give that to our students for homework, which can be found at:

    http://www.cs205.org/resources/hw4.pdf
    (problem 5)

    The goal is to propagate information from a set of seeds. You'll still need a threshold (and in that case, you'll now have 2 thresholds to set!), but you may end up with much better results.

    0 讨论(0)
  • 2021-02-03 12:09

    My proposal assumes you can identify the sudoku cells, which I think, is not asking too much. Trying to apply morphological operators (although I really like them) and/or binarization methods as a first step is the wrong way here, in my opinion of course. Your image is at least partially blurry, for whatever reason (original camera angle and/or movement, among other reasons). So what you need is to revert that, by performing a deconvolution. Of course asking for a perfect deconvolution is too much, but we can try some things.

    One of these "things" is the Wiener filter, and in Matlab, for instance, the function is named deconvwnr. I noticed the blurry to be in the vertical direction, so we can perform a deconvolution with a vertical kernel of certain length (10 in the following example) and also assume the input is not noise free (assumption of 5%) -- I'm just trying to give a very superficial view here, take it easy. In Matlab, your problem is at least partially solved by doing:

    f = imread('some_sudoku_cell.png');
    g = deconvwnr(f, fspecial('motion', 10, 90), 0.05));
    h = im2bw(g, graythresh(g)); % graythresh is the Otsu method
    

    Here are the results from some of your cells (original, otsu, otsu of region growing, morphological enhanced image, otsu from morphological enhanced image with region growing, otsu of deconvolution):

    enter image description here enter image description here enter image description hereenter image description here enter image description here enter image description here
    enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here
    enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here
    enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here
    enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here
    enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

    The enhanced image was produced by performing original + tophat(original) - bottomhat(original) with a flat disk of radius 3. I manually picked the seed point for region growing and manually picked the best threshold.

    For empty cells you get weird results (original and otsu of deconvlution):

    enter image description here enter image description here

    But I don't think you would have trouble to detect whether a cell is empty or not (the global threshold already solves it).

    EDIT:

    Added the best results I could get with a different approach: region growing. I also attempted some other approaches, but this was the second best one.

    0 讨论(0)
  • 2021-02-03 12:15

    You probably want local thresholding. there are some general approaches for that.

    Check the niblack algorithm. See also niblack thresholding. https://stackoverflow.com/a/9891678/461499 We successfully used this for document segmentation.

    0 讨论(0)
提交回复
热议问题