4

enter image description here

Please, refer to this journal article.

The last paragraph of the section 4.1 (Preprocessing) says that, enter image description here

Using [threshold = (mean + std dev)] along with Otsu Thresholding gives the following result,

enter image description here

.

And, without them I obtain the following result,

enter image description here

.

Therefore, I have three questions,

(1) What is the main issue with my implementation of Binary Thresholding?

(2) If Otsu Threshold really gives good result, why did the authors of the article suggest to use [threshold = (mean + std dev)]?

(3) How can I apply a double value as threshold of the Otsu?


enter image description here

Source Code

enter image description here

Here is the GitHub repository.

The most relevant part of the source code is as follows,

    private void thresholdButton_Click(object sender, EventArgs e)
    {
        Bitmap color = (Bitmap)this.inputImagePictureBox.Image;

        Bitmap temp = Grayscale.ToGrayscale((Bitmap)color.Clone());

        ImageStatistics imgStat = new ImageStatistics(temp);

        Histogram histogram = imgStat.Gray;

        double meanPlusStdDev = histogram.Mean + histogram.StdDev;

        OtsuThreshold otsu = new OtsuThreshold();

        int thres = otsu.getOtsuThreshold(temp);//////

        //otsu.Apply(temp, (int)meanPlusStdDev);

        otsu.Apply(temp, thres);

        thresholdedImagePictureBox.Image = temp;
    }
user366312
  • 16,949
  • 65
  • 235
  • 452

2 Answers2

2

I'll only answer (2). I haven't seen anybody use mean + stdev globally, but it is quite common when applying local adaptive thresholding techniques. So instead of calculating a single threshold for the whole image you calculate one for each pixel based on it's neighbourhood. It would make more sense in the application described in the article. Niblack adaptive thresholding for the pixel (x,y) with local mean(x,y) and local stdev(x,y) is:

mean(x,y) + k * stdev(x,y)

Where k is a adjustable parameter. It's quite commonly used in document binarization. Another common one is

t * mean(x,y) + k * stdev(x,y)

Where you can adjust both the local mean and the local stdev thresholds. The point of the stdev term is to give weight to edges. The scratches will always be areas of high local standard deviation, so having a term tied to that should be more effective than simple mean thresholding.

You can also check out the Sauvola algorithm if these seem interesting, it's a further modification on the Niblack algorithm. Check out the concept of integral images if you want to implement these yourself.

Tapio
  • 1,502
  • 1
  • 12
  • 24
2

1) there is no "issue". You are thresholding with different thresholds, then get different results.

2) there is no universal method of finding a global threshold, and global thresholding can be a very poor solution. One slight advantage of the mean/stdev approach is that it leaves an adjustable parameter (coefficient in front of stdev) that gives the implementor a (false) feeling of control.

3) I can't make sense of this question. The threshold is an integer because the pixel values are integer.