C#, Image Binarization (13) - Bimodal Thresholding Algorithm and Source Program of Global Threshold

1. Overview of image binarization

Image binarization is the conversion of a color image into a black and white image. Most computer vision applications convert pictures into binary representations. The more raw an image is, the easier it is for a computer to interpret its underlying features.

Binarization process

In computer memory, all files are usually stored in grayscale with a maximum of 256 different grayscale values ​​from 0 to 255. Each grayscale value produces a different color of the grayscale palette. If you need some information from the document image, you need to do it multiple times. To reduce the time required to extract parts of an image, binary images are more useful.

Binarization is the method of converting any grayscale image (multitone image) into a black and white image (duotone image). To perform binarization, first find the threshold of the grayscale and check if the pixel has a specific grayscale value.

Convert pixels to white if their grayscale value is greater than the threshold. Similarly, pixels are converted to black if their gray value is less than a threshold.

Two types of binarization methods are discussed below −

i. Binarization based on global or individual thresholds

two. Region-based binarization

1. Global or single threshold based binarization: Typically, a global threshold is found for the entire image and a single threshold is used to binarize the image. But in this single-threshold method, the local variance of the image is usually lost or suppressed, which may have some important information or content.

2. Region-based binarization: Another method for binarization is also devised, where the threshold is determined according to the region. In practice, the image is divided into several areas or windows. Each region or window calculates or decides its own local threshold, and then converts its region into a duotone region with the help of its local threshold, according to Saha.

In real scenarios, the binarization process fails because of degradations that may be caused by inefficient image acquisition processes, poor quality of the original source, or uneven illumination on the original source.

Image binarization is turning a color image into a black-and-white one. Most computer vision applications transform the picture into a binary representation. The more unprocessed an image is, the simpler it is for the computer to interpret its underlying characteristics.

Binarization Process
In the computer memory generally all the documents are stored in the form of gray level which has a maximum 256 different gray values from 0 to 255. Each gray value generates the different color of the gray scale palette. If some information is required from the document image, then this is required to process the action number of times. To reduce this time requirement for extracting the part of the image, binary image is more useful.

Binarization is the method of converting any gray – scale image (multi tone image) into black – white image (two tone image) . To perform binarization process, first find the threshold value of gray scale and check whether a pixel having a particular gray value or not.

If the gray value of the pixels is greater than the threshold, then those pixels are converted into the white . Similarly if the gray value of the pixels is lesser than the threshold, then those pixels are converted into the black .

There is two type of binarization method is discuss below –

i. Binarization based on Global or Single Threshold
ii. Binarization based on Region

1. Binarization based on Global or Single Threshold: Normally, find the global threshold for the whole image and binarize the image using single threshold. But in this single threshold method generally the local variance of the image is lost or suppressed which may be having some important information or contents.

2. Binarization based on Region: One another method is also designed for binarization in which threshold decide according to the region. Actually the image is divided into several regions or windows. Each region or window calculate or decide their own local threshold and then convert their region into two – tone region by the help of their local threshold according of the Saha .

The binarization process is failed in the practical scenario because of degradation may be occur due to less efficient acquisition process of image, poor quality of original source or non – uniform illumination over the original source.
 

2. Threshold algorithm and source program based on bimodal average

  For an overview of binary algorithms, please read:

C#, image binarization (01) - a review of binarization algorithms and a catalog of twenty-three algorithms https://blog.csdn.net/beijinghorn/article/details/128425225?spm=1001.2014.3001.5502

For supporting functions, please read:

C#, image binarization (02) - C# source code of some basic image processing functions for image binarization https://blog.csdn.net/beijinghorn/article/details/128425984?spm=1001.2014 . 3001.5502

using System;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Imaging;
 
namespace Legalsoft.Truffer.ImageTools
{
    public static partial class BinarizationHelper
    {
        #region 灰度图像二值化 全局算法 基于双峰平均值的阈值

        /// <summary>
        /// 基于双峰平均值的阈值
        /// 该算法和基于谷底最小值的阈值方法类似,
        /// 只是最后一步不是取得双峰之间的谷底值,
        /// 而是取双峰的平均值作为阈值。
        /// </summary>
        /// <param name="histogram"></param>
        /// <returns></returns>
        public static int Intermodes_Threshold(int[] histogram)
        {
            double[] HistGramC = Histogram_To_Float(histogram);
            double[] HistGramCC = Histogram_To_Float(histogram);

            int Iter = 0;
            while (Is_Dimodal_Histogram(HistGramCC) == false)
            {
                HistGramCC[0] = (HistGramC[0] + HistGramC[0] + HistGramC[1]) / 3;
                for (int i = 1; i < 255; i++)
                {
                    HistGramCC[i] = (HistGramC[i - 1] + HistGramC[i] + HistGramC[i + 1]) / 3;
                }
                HistGramCC[255] = (HistGramC[254] + HistGramC[255] + HistGramC[255]) / 3;
                System.Buffer.BlockCopy(HistGramCC, 0, HistGramC, 0, 256 * sizeof(double));
                Iter++;
                if (Iter >= 10000)
                {
                    return -1;
                }
            }

            int[] Peak = new int[2];
            for (int i = 1, Index = 0; i < 255; i++)
            {
                if (HistGramCC[i - 1] < HistGramCC[i] && HistGramCC[i + 1] < HistGramCC[i])
                {
                    Peak[Index++] = i - 1;
                }
            }
            return ((Peak[0] + Peak[1]) / 2);
        }

        public static void Intermodes_Algorithm(byte[,] data)
        {
            int[] histogram = Gray_Histogram(data);
            int threshold = Intermodes_Threshold(histogram);
            Threshold_Algorithm(data, threshold);
        }

        #endregion    
    }
}
 

3. Calculation effect of the threshold algorithm based on bimodal average

Guess you like

Origin blog.csdn.net/beijinghorn/article/details/128521963