Click here to Skip to main content
15,886,578 members
Articles / Artificial Intelligence

AForge.NET open source framework

Rate me:
Please Sign up or sign in to vote.
4.97/5 (150 votes)
16 May 2007GPL311 min read 828.4K   48.3K   346  
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 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;
	using AForge;

	/// <summary>
	/// Saturation adjusting in HSL color space
	/// </summary>
	/// 
	/// <remarks>The filter operates in <b>HSL</b> color space and adjusts
	/// pixels saturation value.</remarks>
	/// 
	public class SaturationCorrection : IFilter, IInPlaceFilter
	{
		private HSLLinear	baseFilter = new HSLLinear( );
		private double		adjustValue;	// [-1, 1]

		/// <summary>
		/// Saturation adjust value in the range of [-1, 1]. Default value is 0.1.
		/// </summary>
		public double AdjustValue
		{
			get { return adjustValue; }
			set
			{
				adjustValue = Math.Max( -1.0, Math.Min( 1.0, value ) );

				// create saturation filter
				if ( adjustValue > 0 )
				{
					baseFilter.InSaturation		= new DoubleRange( 0.0, 1.0 - adjustValue );
					baseFilter.OutSaturation	= new DoubleRange( adjustValue, 1.0 );
				}
				else
				{
					baseFilter.InSaturation		= new DoubleRange( -adjustValue, 1.0 );
					baseFilter.OutSaturation	= new DoubleRange( 0.0, 1.0 + adjustValue );
				}
			}
		}

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

		/// <summary>
		/// Initializes a new instance of the <see cref="SaturationCorrection"/> class
		/// </summary>
		/// 
		/// <param name="adjustValue">Saturation adjust value</param>
		/// 
		public SaturationCorrection( double adjustValue )
		{
			AdjustValue = adjustValue;
		}

		/// <summary>
		/// Apply filter to an image
		/// </summary>
		/// 
		/// <param name="image">Source image to apply filter to</param>
		/// 
		/// <returns>Returns filter's result obtained by applying the filter to
		/// the source image</returns>
		/// 
		/// <remarks>The method keeps the source image unchanged and returns the
		/// the result of image processing filter as new image.</remarks> 
		///
		public Bitmap Apply( Bitmap image )
		{
			return baseFilter.Apply( image );
		}

		/// <summary>
		/// Apply filter to an image
		/// </summary>
		/// 
		/// <param name="imageData">Source image to apply filter to</param>
		/// 
		/// <returns>Returns filter's result obtained by applying the filter to
		/// the source image</returns>
		/// 
		/// <remarks>The filter accepts birmap data as input and returns the result
		/// of image processing filter as new image. The source image data are kept
		/// unchanged.</remarks>
		/// 
		public Bitmap Apply( BitmapData imageData )
		{
			return baseFilter.Apply( imageData );
		}

		/// <summary>
		/// Apply filter to an image
		/// </summary>
		/// 
		/// <param name="image">Image to apply filter to</param>
		/// 
		/// <remarks>The method applies the filter directly to the provided
		/// image.</remarks>
		/// 
		public void ApplyInPlace( Bitmap image )
		{
			baseFilter.ApplyInPlace( image );
		}

		/// <summary>
		/// Apply filter to an image
		/// </summary>
		/// 
		/// <param name="imageData">Image to apply filter to</param>
		/// 
		/// <remarks>The method applies the filter directly to the provided
		/// image data.</remarks>
		/// 
		public void ApplyInPlace( BitmapData imageData )
		{
			baseFilter.ApplyInPlace( imageData );
		}
	}
}

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)


Written By
Software Developer IBM
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, Computer Vision Sandbox, cam2web, ANNT, etc.

Comments and Discussions