zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C#,图像二值化(04)——全局阈值的凯勒算法(Kittler Thresholding)及源程序

c#算法 图像 全局 04 阈值 源程序 二值化
2023-09-11 14:15:48 时间

 

1、Kittler算法(最小误差法)概述

最小误差法是 J. Kittler & J. Illingworth 1986年在《MINIMUM ERROR THRESHOLDING》文章中提出的一种基于直方图的阈值分割方法,简称 Kittler 算法。其思想:假设灰度图像由目标和背景组成,且目标和背景满足一混合高斯分布,计算目标和背景的均值、方差,根据最小分类误差思想得到的最小误差目标函数,取目标函数最小时的阈值即为最佳阈值。按此阈值将图像分割为二值图像。

Kittler算法与Otsu方法效果接近,但速度更快,更适宜应用于像素质量较高的图像中。
Kittler算法的中心思想是,计算整幅图像的梯度灰度的平均值,以此平均值做为阈值。
 

 二值算法综述请阅读:

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

2、Kittler算法源代码

using System;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;

namespace Legalsoft.Truffer.ImageTools
{
    public static partial class BinarizationHelper
    {
        #region 灰度图像二值化 全局算法 Kittler 算法

        /// <summary>
        /// Kittler算法
        /// </summary>
        /// <param name="data"></param>
        public static void Kittler_Algorithm(byte[,] data)
        {
            int height = data.GetLength(0);
            int width = data.GetLength(1);
            double sumGrads = 0.0;
            double sumGrayGrads = 0.0;
            for (int y = 1; y < height - 1; y++)
            {
                for (int x = 1; x < width - 1; x++)
                {
                    double Grads = Math.Max(Math.Abs(data[y - 1, x] - data[y + 1, x]), Math.Abs(data[y, x - 1] - data[y, x + 1]));
                    sumGrads += Grads;
                    sumGrayGrads += Grads * (data[y, x]);
                }
            }
            int threshold = (int)(sumGrayGrads / sumGrads);
            Threshold_Algorithm(data, threshold);
        }

        #endregion
    }
}

The Kittler binarization method is a classic binarization method based on histogram. ... The idea isfirst cut the image into small patches of the same sizeand then use the method mentioned in the paper to calculate a local (relative to the entire imagethreshold for each small patchand then use bilateral interpolation 

3、Kittler算法的二值化效果以及与基本阈值算法的对比

 The Kittler binarization method is a classic binarization method based on histogramProposed by JKittler in the paper " Minimum Error Thresholdingpublished in 1986 .