Search This Blog

Sunday, June 5, 2011

HSL vs RGB Aforge.NET Color Filter

Yes, I am obsessed with color filters. And looks like that is what usually the hello world in image processing world to understand your image formats. Initially I have done color filters that are based on RGB. Last week in my lab we ran into an issue when we printed 6 blocks of color on white paper and kept it under a camera and used of filter to see how it works. Guess what? the filter showed red with magenta and other colors! That is not good. So why is it happening?
When we do a filter based on RGB, it looks for percentage of R, G and B in the a particular pixel. So it is a kind of relation. Let me give you a nice example
Assume I want to detect red color but I also have magenta color in the same image. My filter shows magenta as red! So I go to wikipedia ( and see why is it so and get something like this
r, g, b)
(255, 0, 255)

h, s, v)
(300°, 100%, 100[1]%)

So when I used red filter in RGB space the magenta has 255 for R and 255 for B. So it will show up in both Red and Blue filter working in magenta.
But in HSV the value is 300. That is only one number. So when I filter my image in HSV and say 300 it will show only Magenta. For red it will be somewhere between 0 to 20. How I know the value, simple this image given below taken from Wikipedia ( will help
File:Hsl-hsv models.svg

I know we are all lazy, so here is the source code to grab image from webcam
Download  (Source code to grab image from Web Cam using C# )(
After that we use AForge library by adding the Aforge.Imaging.dll to convert RGB to HSL. Added the following code for HSL filter and you’ll see the prefomance

void SelectedCam_NewFrame(object sender, NewFrameEventArgs eventArgs)
Bitmap image = (Bitmap)eventArgs.Frame.Clone();

//Reference :

// set color ranges to keep red-orange
filter.Hue = new IntRange(0, 20);
filter.Saturation = new DoubleRange(0.5, 1);

// apply the filter

// display in picture box
pictureBox1.Image = image;

Let me show how the image worked.
Given below is the image from my webcam that I am going to filter using HSL


I have added a magenta color printed in a paper and kept it at the background. Because you will see the real difference when you use a RGB to filter vs HSL for this image. I am not doing the RGB, but I will be giving the source code for this at the end of the post. So you are free to try based on the previous posts. After applying the HSL filter lets look how it looks



There is no Magenta or any other color being showed. By tweaking the value you can get more better results.

You can download the source code by clicking down below

Click Here for Source Code for HSLFilter using Aforge

Wednesday, February 16, 2011


DLP RFID 1 API for IEEE15693 C# .NET


Download Here

I have been working on a project for the special education school. My project involves the use of RFID reader from DLP Design ( Being a typical .NET programmer, I wanted to develop my application in C# windows application using DLP RFID1 reader. I took the sample code from the DLP site ( which was given in C++. I tried to write a wrapper around the existing library, but then came across a site/blog ( who wrote about the details of the communication protocol. So I wrote according the to document and it worked!!! My system had a card already made and it runs on IEEE5693. So I wrote my DLP RFID1 .NET library only for this type of tag. I am attaching the download link for the library and also giving a screenshot tutorial of the library usage.

Add Reference as shown…


Add the files that you downloaded


And here is the code


using System;

using System.Text;

using RFIDCard;


if (!CardReader.DetectReader())





Sorry for poor documentation.

There are only 2 usable functions and 1 string variable.

Functions (static):


String Variable for error feedback (static):



Download Here


Leave comments.