Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

AForge.NET open source framework

, 16 May 2007
The article describes an open source C# framework for researchers in the areas of Computer Vision and Artificial Intelligence - image processing, neural networks, genetic algorithms, etc.
aforge_demo.zip
aforge_demo
Docs
AForge.Controls.chm
AForge.Core.chm
AForge.Genetic.chm
AForge.Imaging.chm
AForge.Math.chm
AForge.Neuro.chm
Release
AForge.Controls.dll
AForge.dll
AForge.Genetic.dll
AForge.Imaging.dll
AForge.Math.dll
AForge.Neuro.dll
Samples
Genetic
Approximation
AForge.Controls.dll
AForge.dll
AForge.Genetic.dll
Approximation.exe
Data Samples
sample1.csv
sample2.csv
Optimization1D
AForge.Controls.dll
AForge.dll
AForge.Genetic.dll
Optimization1D.exe
TimeSeries
AForge.Controls.dll
AForge.dll
AForge.Genetic.dll
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
TimeSeries.exe
TSP
AForge.Controls.dll
AForge.dll
AForge.Genetic.dll
TSP.exe
Imaging
FiltersDemo
AForge.dll
AForge.Imaging.dll
AForge.Math.dll
FiltersDemo.exe
TexturesDemo
AForge.dll
AForge.Imaging.dll
AForge.Math.dll
TexturesDemo.exe
Neuro
Back Propagation
Approximation
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Approximation.exe
Data Samples
sample1.csv
sample2.csv
TimeSeries
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
TimeSeries.exe
XORProblem
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
XORProblem.exe
Simple
Delta Rule Learning
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
and.csv
cube.csv
or.csv
sample1.csv
sample2.csv
One-Layer Perceptron Classifier
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
sample1.csv
sample2.csv
Perceptron Classifier
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
and.csv
cube.csv
or.csv
SOM
2DOrganizing
2DOrganizing.exe
AForge.dll
AForge.Neuro.dll
Color
AForge.dll
AForge.Neuro.dll
Color.exe
TSP
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
TSP.exe
aforge_src.zip
aforge_src
Samples
Genetic
Approximation
App.ico
Data Samples
sample1.csv
sample2.csv
Optimization1D
App.ico
TimeSeries
App.ico
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
TSP
App.ico
Imaging
FiltersDemo
App.ico
TexturesDemo
Properties
Neuro
Back Propagation
Approximation
App.ico
Data Samples
sample1.csv
sample2.csv
TimeSeries
App.ico
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
XORProblem
App.ico
Simple
Delta Rule Learning
App.ico
Data Samples
and.csv
cube.csv
or.csv
sample1.csv
sample2.csv
One-Layer Perceptron Classifier
App.ico
Data Samples
sample1.csv
sample2.csv
Perceptron Classifier
App.ico
Data Samples
and.csv
cube.csv
or.csv
SOM
2DOrganizing
App.ico
Color
App.ico
TSP
App.ico
Sources
Controls
bin
Debug
obj
Debug
TempPE
Core
bin
Debug
obj
Debug
TempPE
Docs Projects
AForge.Controls.shfb
AForge.Core.shfb
AForge.Genetic.shfb
AForge.Imaging.shfb
AForge.Math.shfb
AForge.Neuro.shfb
Genetic
bin
Debug
Chromosomes
GP
Fitness Functions
obj
Debug
TempPE
Selection Algorithms
Imaging
bin
Debug
Filters
2 Source filters
Adaptive Binarization
Base classes
Binarization
Color Filters
Convolution
Edge Detectors
HSL Filters
Morphology
Other
Transform
YCbCr Filters
Images
sample1.jpg
sepia.jpg
obj
Debug
TempPE
Textures
Math
bin
Debug
obj
Debug
TempPE
Neuro
Activation Functions
bin
Debug
Images
sigmoid.bmp
sigmoid_bipolar.bmp
threshold.bmp
Layers
Learning
Networks
Neurons
obj
Debug
TempPE
// AForge Image Processing Library
//
// Copyright � Andrew Kirillov, 2005-2006
// andrew.kirillov@gmail.com
//

namespace AForge.Imaging.Filters
{
	using System;
	using System.Drawing;
	using System.Drawing.Imaging;

	/// <summary>
	/// Binarization with thresholds matrix
	/// </summary>
	public class OrderedDithering : FilterAnyToGray
	{
		private int rows = 4;
		private int cols = 4;

		private byte[,] matrix = new byte[4, 4]
		{
			{  15, 143,  47, 175 },
			{ 207,  79, 239, 111 },
			{  63, 191,  31, 159 },
			{ 255, 127, 223,  95 }
		};

		/// <summary>
		/// Initializes a new instance of the <see cref="OrderedDithering"/> class
		/// </summary>
		/// 
		public OrderedDithering( ) { }

		/// <summary>
		/// Initializes a new instance of the <see cref="OrderedDithering"/> class
		/// </summary>
		/// 
		/// <param name="matrix">Thresholds matrix</param>
		/// 
		public OrderedDithering( byte[,] matrix )
		{
			rows = matrix.GetLength( 0 );
			cols = matrix.GetLength( 1 );

			this.matrix = matrix;
		}

		/// <summary>
		/// Process the filter on the specified image
		/// </summary>
		/// 
		/// <param name="sourceData">Source image data</param>
		/// <param name="destinationData">Destination image data</param>
		/// 
		protected override unsafe void ProcessFilter( BitmapData sourceData, BitmapData destinationData )
		{
			// get width and height
			int width = sourceData.Width;
			int height = sourceData.Height;

			int srcOffset = sourceData.Stride - ( ( sourceData.PixelFormat == PixelFormat.Format8bppIndexed ) ? width : width * 3 );
			int dstOffset = destinationData.Stride - width;

			// do the job
			byte * src = (byte *) sourceData.Scan0.ToPointer( );
			byte * dst = (byte *) destinationData.Scan0.ToPointer( );

			if ( sourceData.PixelFormat == PixelFormat.Format8bppIndexed )
			{
				// graysclae binarization
				for (int y = 0; y < height; y++)
				{
					for (int x = 0; x < width; x++, src ++, dst ++)
					{
						*dst = (byte)( ( *src <= matrix[( y % rows ), ( x % cols )] ) ? 0 : 255 );
					}
					src += srcOffset;
					dst += dstOffset;
				}
			}
			else
			{
				// RGB binarization
				for (int y = 0; y < height; y++)
				{
					for (int x = 0; x < width; x++, src += 3, dst ++)
					{
						// grayscale value using BT709
						*dst = (byte)( ( (byte)( 0.2125 * src[RGB.R] + 0.7154 * src[RGB.G] + 0.0721 * src[RGB.B] ) <=
							matrix[( y % rows ), ( x % cols )] ) ? 0 : 255 );
					}
					src += srcOffset;
					dst += dstOffset;
				}
			}
		}
	}
}

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
Web03 | 2.8.140916.1 | Last Updated 16 May 2007
Article Copyright 2006 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid