4

Does anybody knows about post-processing algorithms to remove ghost objects from binarized image? The problem: When I binarize image using for example niblack method or bernsen, it produces many noise. I red book or internet articles about binarization, and they all say that the post-processing step is needed in Niblack and other's binarization method, But they don't say what is it, post-processing operation. So please, if someone knows, tel me. EDIT: Original image:

alt text http://i.piccy.info/i4/20/63/b970ab2ca66e997f421e969a1657.bmp

Bernsen threshold winsize 31, contrast difference 15:

alt text http://i.piccy.info/i4/32/55/2f1e0293311119986bd49529e579.bmp

Bernsen threshold winsize 31, contrast difference 31:

alt text http://i.piccy.info/i4/2a/13/774508890030b93201458986bbd2.bmp

Niblack method window size-15, k_value 0.2:

alt text http://i.piccy.info/i4/12/4f/fa6fc09bcba7a7e3245d670cbfa5.bmp

Niblack method window size-31, k_value 0.2:

alt text http://i.piccy.info/i4/c0/fd/1f190077abba2aeea89398358fc0.bmp

EDIT2: As you see, the Niblack threshold is making many noise. And if I make the window size less, the black squares became a little white inside. The Bernsen is better - less noise, but even if I make the contrast difference bigger, but there is one problem, I just can't produce image right now, in words, the problem: if image contains some objects with color close to white color, and the background is white, so if there is a region (for examle line) with black color, then this method ignores the objects and result is wrong. That is because Bernsen method use this formula: at each pixel calculate the contrast difference diff = maximum_grayscale_value - minimum_grayscale_value and then the diff is used to calculate threshold value, but in the case that I wrote above, we have maximum value of 255 and minimum value of 0. So threshold will be 128, But actual object color is above the 128 (near white color).

So I need to use some post-processing operations to make binarization correctly. Any thoughts?

maximus
  • 4,201
  • 15
  • 64
  • 117
  • Example image, please! (both before and after binarization). Depending on that, some morphological clean-up might do. – AVB Mar 02 '10 at 13:42
  • I added images, later will comment them more, No timenow – maximus Mar 03 '10 at 04:33
  • I added more information, The method realization is correct, but what is the problem here, and what should be done to make binarization better? – maximus Mar 03 '10 at 15:47

3 Answers3

2

Complete Python program using K-means, a tool meant for finding optimal quantization intervals:

from scipy.misc import imread, imsave
def kmeans(file_in, file_out, maxiter):
    X = imread(file_in)
    thresh = X.mean()
    for iter in range(maxiter):
        thresh = (X[X<thresh].mean() + X[X>=thresh].mean())/2.0
    X[X<thresh] = 0
    X[X>=thresh] = 255
    imsave(file_out, X)
    return X, thresh

During each iteration, K-means computes the center of each "cluster" then reassigns elements to clusters based upon the recomputed centers. In the simple case where each element (i.e., pixel) is one-dimensional, and only two clusters are required, the threshold is simply the average of the two cluster centers.

I should add that this method works for the example image you posted, but may not for others (such as the one you posted in another question). But without further information, I think that this solution works.

Output:

binary.bmp http://up.stevetjoa.com/binary.bmp

Steve Tjoa
  • 59,122
  • 18
  • 90
  • 101
  • Seems that this algorithm behaves like global thresholding, but what if I decide to binarize other images where global thresholding is wrong? – maximus Mar 04 '10 at 04:56
  • Yeah, then you may need something else. I was only responding to this particular question with the given image as an example, in which case my solution works. – Steve Tjoa Mar 04 '10 at 06:26
  • OK, I got an idea, but not sure about speed and the idea itself. So, if by some algorithm we can get a number N, indicating how many clusters we need in a certain image, And then use K-Means algorithm and get not binarized, but something like segmented image, number of segments is N. Actually the segment in this case means a region whose pixels belong to a certain region. So then we can work with more simple image. The next step can be a binarization which I think is easier than before, or use that segments separately. So can you tell me what do you think, will it work? – maximus Mar 05 '10 at 01:51
  • In my case the K-means are not used for computing threshold, but for segmentation. – maximus Mar 05 '10 at 01:55
  • Right, I had considered the same thing. But that solution -- using K-means for *spatial* segmentation -- is far less robust. Finding N is not easy. In the process of finding N, if you were able to do it, you would most likely have also found the clusters themselves. – Steve Tjoa Mar 05 '10 at 05:37
  • But this Niblack algorithm (which I was not familiar with before, but now I am) itself does not seem robust. To me, the formular is heuristically yet not rigorously motivated. I question its ability to adapt to different images. – Steve Tjoa Mar 05 '10 at 05:39
  • Yes thats right. OK, then what are the binarization methods that can solve the problem? The uneven illumination problem in binarization was supposed to be solved by using adaptive local thresholding, but it is not doing its job well enough. – maximus Mar 06 '10 at 10:32
0

It really sounds like your problem is a segmentation problem... what are the types of images you're pumping through?

Btw, how do I comment on the question instead of answering it?

jghost
  • 94
  • 4
  • What do you mean by type of images? They are made by camera in different conditions, like uneven illumination and so on. There is a text and Niblack was supposed to be one of the best to deal with text images, but it is very noisy. The question has a add comment button, you can see it at the bottom of question. Under the comments that are already posted there. – maximus Mar 04 '10 at 10:41
  • What I mean by type is: are they synthetic textures, biological images, etc. Each has a very different approach to solving it. Some are good with frequency domain solutions while others are good with geometrically based solutions. It also depends on all kinds of other factors... like color balancing, radial distortion, etc. – jghost Mar 04 '10 at 18:23
0

The question might be outdated, but for those who still could not find the answer the method that should be used in these situations, namely with fast-varying background images is NOT Local Gray Level thresh but Local Feature Thresholding, which analyses images not by local gray level but with Stroke Width method. U can look for it up in the net.