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
Some ideas about optical character recognition using neural networks.
Prize winner in Competition "C# Jul 2005"
// AForge Math Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.Math
{
	using System;
	
	/// <summary>
	/// Complex number
	/// </summary>
	public struct Complex
	{
		public float	Re;		// real component
		public float	Im;		// imaginary component
		
		// Get zero value
		public static Complex Zero
		{
			get { return new Complex(0, 0); }
		}
		
		// Get magnitude (absolute) value
		public float Magnitude
		{
			get { return (float) System.Math.Sqrt(Re * Re + Im * Im); }
		}

		// Get phase value
		public float Phase
		{
			get { return (float) System.Math.Atan(Im / Re); }
		}
		
		// Get squred magnitude value
		public float SquaredMagnitude
		{
			get { return (Re * Re + Im * Im); }
		}
	
	
		// Constructors
		public Complex(float re, float im)
		{
			this.Re = re;
			this.Im = im;
		}
		public Complex(Complex c)
		{
			this.Re = c.Re;
			this.Im = c.Im;
		}
		
		// Get complex number as string
		public override string ToString()
		{
			return String.Format("{0}{1}{2}i", Re, ((Im < 0) ? '-' : '+'), Math.Abs(Im));
		}
		
		// Add two complex numbers
		public static Complex operator+(Complex a, Complex b)
		{
			return new Complex(a.Re + b.Re, a.Im + b.Im);
		}

		// Subtract two complex numbers
		public static Complex operator-(Complex a, Complex b)
		{
			return new Complex(a.Re - b.Re, a.Im - b.Im);
		}
		
		// Multiply two complex numbers
		public static Complex operator*(Complex a, Complex b)
		{
			return new Complex(
				a.Re * b.Re - a.Im * b.Im,
				a.Re * b.Im + a.Im * b.Re);
		}

		// Divide one complex number by another
		public static Complex operator/(Complex a, Complex b)
		{
			float divider = b.Re * b.Re + b.Im * b.Im;
			
			if (divider == 0)
				throw new DivideByZeroException();
		
			return new Complex(
				(a.Re * b.Re + a.Im * b.Im) / divider,
				(a.Im * b.Re - a.Re * b.Im) / divider);
		}
	}
}

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 | Mobile
Web01 | 2.8.140814.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid