Home > ASP.NET, C#, Graphics, Programming, Tips & Tricks > C# Image Processing with AForge.NET Framework

C# Image Processing with AForge.NET Framework

A couple of days ago i found a great framework called AForge.NET.

AForge.NET is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence – image processing, neural networks, genetic algorithms, machine learning, robotics, etc.

The framework is published under LGPL v3 license and comprised by the set of libraries and sample applications, which demonstrate their features:

  • AForge.Imaging – library with image processing routines and filters
  • AForge.Vision – computer vision library
  • AForge.Neuro – neural networks computation library
  • AForge.Genetic – evolution programming library
  • AForge.MachineLearning – machine learning library
  • AForge.Robotics – library providing support of some robotics kits
  • AForge.Video – set of libraries for video processing

The framework is provided not only with different libraries and their sources, but with many sample applications, which demonstrate the use of this framework, and with documentation help files, which are provided in HTML Help format.

As you can see this framework contains varied libraries, but as for me i was especially interested in the image processing routines and filters.

Let’s see  the  CannyEdgeDetector in action.

using AForge.Imaging.Filters;

// Loading some file
using (Bitmap SampleImage = (Bitmap)Image.FromFile("test.jpg"))
{
    // We must convert it to grayscale because
    // the filter accepts 8 bpp grayscale images
    Grayscale GF = new Grayscale(0.2125, 0.7154, 0.0721);
    using (Bitmap GSampleImage = GF.Apply(SampleImage))
    {
        // Saving the grayscale image, so we could see it later
        GSampleImage.SaveAsJpeg("testBW.jpg", 100);

        // Detecting image edges and saving the result
        CannyEdgeDetector CED = new CannyEdgeDetector(0,70);
        CED.ApplyInPlace(GSampleImage);
        GSampleImage.SaveAsJpeg("testEDGED.jpg",100);
    }
}

// SaveAsJpeg is an extension method i wrote to be able to save
// Jpeg images with parametrized quality
// You can use Image.Save ("image.jpg", ImageFormat.Jpeg) instead

Now, let see the results ( click the image to see full size )

The result is great, and of course we can modify the threshold levels to gain even better results.
As for other filter and effects there are many of them in this library.
There are Noise generators, color correction filters, smoothing filters and more.

Sure, it’s no Photoshop, but i must say it’s very close to it.

Hope you will find this useful, I did.

VN:F [1.7.7_1013]
Rating: 4.3/5 (4 votes cast)
C# Image Processing with AForge.NET Framework4.354

A few posts you might find interesting:

  1. Image Resizing in C#
  2. C# Rectangle Packing
  3. C# Set method timeout using Generics
  4. SpeedTrace – .NET Profiler and Tracer
  5. C# Inheritance Question

  1. Jimmi
    July 21st, 2009 at 14:02 | #1

    I installed the latest version of Aforg.net (2.0 beta). Although there is an option to do full installation (including source code) but i tried several times but no source codes was included. I went to one of the link provided by the author and I could manege to download very old version of source code. can someone help me how I can have access to latest version of source code.

    UN:F [1.7.7_1013]
    Rating: 1.0/5 (1 vote cast)
  2. July 21st, 2009 at 14:40 | #2

    @Jimmi
    You can download the lastest version at http://code.google.com/p/aforge/downloads/list

    After installing it (Full mode) you can find the source code in the following directory : C:\Program Files\AForge.NET\Sources\

    UA:F [1.7.7_1013]
    Rating: 1.0/5 (1 vote cast)
  3. Jimmi
    July 22nd, 2009 at 02:20 | #3

    @Xander
    Many thanks for your reply. This time I did install it on another computer and be able to have access to source code.Thanks.

    UN:F [1.7.7_1013]
    Rating: 1.0/5 (1 vote cast)
  1. July 10th, 2009 at 09:21 | #1

Subscribe without commenting

SEO Powered by Platinum SEO from Techblissonline