C#,图像二值化(10)——全局阈值的灰度平均值算法(Gray-Average Thresholding)及其源代码

C#,图像二值化(10)——全局阈值的灰度平均值算法(Gray-Average Thresholding)及其源代码_第1张图片

An image histogram is a gray-scale value distribution showing the frequency of occurrence of each gray-level value. For an image size of 1024 × 1024 × 8 bits, the abscissa ranges from 0 to 255; the total number of pixels is equal to 1024 × 1024. Modification of original histograms very often is used in image enhancement procedures.

An image histogram is chart representation of the distribution of intensities in an Indexed image or grayscale image. It shows how many times each intensity value in image occurs. 

There are two ways to plot a Histogram of an image: 

Method 1: In this method, the x-axis has grey levels/ Intensity values and the y-axis has the number of pixels in each grey level. The Histogram value representation of the above image is: 

Histogram-of-an-image-Method-1

Explanation: The above image has 1, 2, 3, 4, 5, 6, and 8 as the intensity values and the occurrence of each intensity value in the image matrix is 2, 1, 3, 2, 2, 3 and 3 respectively so according to intensity value and occurrence of that particular intensity we mapped them into a Graph. 

Method 2: In this method, the x-axis represents the grey level, while the y-axis represents the probability of occurrence of that grey level. 

Probability Function: 

Probability-Function

Below table shows the probability of each intensity level of an pixel.

改编自:

十三种基于直方图的图像全局二值化算法原理、实现、代码及效果https://www.cnblogs.com/Imageshop/p/3307308.html

C#,图像二值化(10)——全局阈值的灰度平均值算法(Gray-Average Thresholding)及其源代码_第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
    {
        /// 
        /// 十三种基于直方图的图像全局二值化算法原理、实现、代码及效果。
        /// https://www.cnblogs.com/Imageshop/p/3307308.html
        /// 灰度平均值
        /// 
        /// 
        /// 
        public static int Mean_Threshold(int[] histogram)
        {
            return (int)(Histogram_Sum(histogram, 1) / Histogram_Sum(histogram));
        }

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

        #endregion
    }
}

C#,图像二值化(10)——全局阈值的灰度平均值算法(Gray-Average Thresholding)及其源代码_第3张图片

你可能感兴趣的:(C#算法演义,Algorithm,Recipes,C#实用代码,Coding,Recipes,c#,算法,开发语言)