Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Neural Network OCR

, 11 Aug 2005 GPL3
Some ideas about optical character recognition using neural networks.
neuroocr_demo.zip
AForge.Imaging.dll
AForge.Math.dll
AForge.NeuralNet.dll
NeuroOCR.exe
SourceGrid2.dll
SourceLibrary.dll
neuroocr_src.zip
AForge
Math
Math.csproj.user
NeuralNet
Learning
NeuralNet.csproj.user
NeuroOCR
App.ico
NeuroOCR.csproj.user
References
AForge.Imaging.dll
SourceGrid2.dll
SourceLibrary.dll
// AForge Math Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.Math
{
	using System;

	/// <summary>
	/// Set of statistics functions
	/// </summary>
	public class Statistics
	{
		/// <summary>
		/// Calculate mean value
		/// 
		/// Input: histogram array
		/// </summary>
		public static double Mean(int[] values)
		{
			int		v;
			int		mean = 0;
			int		total = 0;

			// for all values
			for (int i = 0, n = values.Length; i < n; i++)
			{
				v = values[i];

				// accumulate mean
				mean += i * v;
				// accumalate total
				total += v;
			}

			return (double) mean / total;
		}


		/// <summary>
		/// Calculate standard deviation
		/// 
		/// Input: histogram array
		/// </summary>
		public static double StdDev(int[] values)
		{
			double	mean = Mean(values);
			double	stddev = 0;
			double	t;
			int		v;
			int		total = 0;

			// for all values
			for (int i = 0, n = values.Length; i < n; i++)
			{
				v = values[i];
				t = (double) i - mean;

				// accumulate mean
				stddev += t * t * v;
				// accumalate total
				total += v;
			}

			return Math.Sqrt(stddev / total);
		}


		/// <summary>
		/// Calculate median value
		/// 
		/// Input: histogram array
		/// </summary>
		public static int Median(int[] values)
		{
			int total = 0, n = values.Length;

			// for all values
			for (int i = 0; i < n; i++)
			{
				// accumalate total
				total += values[i];
			}

			int halfTotal = total / 2;
			int median, v;

			// find median value
			for (median = 0, v = 0; median < n; median++)
			{
				v += values[median];
				if (v >= halfTotal)
					break;
			}

			return median;
		}


		/// <summary>
		/// Get range around median containing specified percentile of values
		/// 
		/// Input: histogram array
		/// </summary>
		public static Range GetRange(int[] values, double percent)
		{
			int total = 0, n = values.Length;

			// for all values
			for (int i = 0; i < n; i++)
			{
				// accumalate total
				total += values[i];
			}

			int min, max, v;
			int h = (int)(total * (percent + (1 - percent) / 2));

			// get range min value
			for (min = 0, v = total; min < n; min++)
			{
				v -= values[min];
				if (v < h)
					break;
			}
			// get range max value
			for (max = n - 1, v = total;  max >= 0; max--)
			{
				v -= values[max];
				if (v < h)
					break;
			}
			return new Range(min, max);
		}


		/// <summary>
		/// Calculate an entropy
		/// 
		/// Input: histogram array
		/// </summary>
		public static double Entropy(int[] values)
		{
			int total = 0;

			for (int i = 0, n = values.Length; i < n; i++)
			{
				total += values[i];
			}

			return Entropy(values, total);
		}
		public static double Entropy(int[] values, int total)
		{
			int		n = values.Length;
			double	e = 0;
			double	p;

			// for all values
			for (int i = 0; i < n; i++)
			{
				// get item probability
				p = (double) values[i] / total;
				// calculate entropy
				if (p != 0)
					e += (-p * Math.Log(p, 2));
			}
			return e;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Andrew Kirillov
Software Developer (Senior) Cisco Systems
United Kingdom United Kingdom
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET.
 
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid