1、图像二值化概述
图像二值化是将彩色图像转换为黑白图像。大多数计算机视觉应用程序将图片转换为二进制表示。图像越是未经处理,计算机就越容易解释其基本特征。
二值化过程
在计算机存储器中,所有文件通常以灰度级的形式存储,灰度级具有从0到255的最大256个不同灰度值。每个灰度值生成灰度调色板的不同颜色。如果需要文档图像中的某些信息,则需要进行多次操作。为了减少提取图像部分所需的时间,二进制图像更有用。
二值化是将任何灰度图像(多色调图像)转换为黑白图像(双色调图像)的方法。要执行二值化处理,首先找到灰度的阈值,并检查像素是否具有特定的灰度值。
如果像素的灰度值大于阈值,则将这些像素转换为白色。类似地,如果像素的灰度值小于阈值,则这些像素被转换为黑色。
下面讨论了两种类型的二值化方法——
i、 基于全局或单个阈值的二值化
二。基于区域的二值化
1.基于全局或单个阈值的二值化:通常,找到整个图像的全局阈值,并使用单个阈值对图像进行二值化。但是在这种单阈值方法中,图像的局部方差通常丢失或被抑制,这可能具有一些重要的信息或内容。
2.基于区域的二值化:还设计了另一种用于二值化的方法,其中阈值根据区域来确定。实际上,图像被划分为几个区域或窗口。每个区域或窗口计算或决定自己的局部阈值,然后根据Saha,借助其局部阈值将其区域转换为双色调区域。
在实际场景中,二值化过程失败,因为可能由于图像采集过程效率低、原始源质量差或原始源上的照明不均匀而导致退化。
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、基于双峰平均值的阈值算法与源程序
二值算法综述请阅读:
C#,图像二值化(01)——二值化算法综述与二十三种算法目录https://blog.csdn.net/beijinghorn/article/details/128425225?spm=1001.2014.3001.5502
支持函数请阅读:
C#,图像二值化(02)——用于图像二值化处理的一些基本图像处理函数之C#源代码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
}
}