Using c# code and Aforge library we can easily detect and extract the pupil from an eye image.
Algorithm
step 1 – first take the eye image
step 2 – make it invert
step 3- convert it to gray scale
step 4 – use binary filter taking threshold value 220
step 5 – find the biggest object
step 6 – find that objects center point and height
step 7 – cut a circle from that point taking radius as 2.5 multiply of height
coding steps
first take the eye image
System.Drawing.Bitmap aq = (Bitmap)pictureBox1.Image;
then make it invert
Invert a = new Invert(); aq= a.Apply(aq); AForge.Imaging.Image.FormatImage(ref aq);
now we make it grayscale
IFilter filter = Grayscale.CommonAlgorithms.BT709; aq = filter.Apply(aq);
now we make it binary using threshold 220
Threshold th = new Threshold(220); aq = th.Apply(aq);
now we have to find the biggest object in the binary image
BlobCounter bl = new BlobCounter(aq); int i = bl.ObjectsCount; ExtractBiggestBlob fil2 = new ExtractBiggestBlob(); fil2.Apply(aq);
now we will find the start position and height of the biggest object/eye pupil
int x = 0; int y = 0; int h = 0; if (i > 0) { fil2.Apply(aq); x = fil2.BlobPosition.X; y = fil2.BlobPosition.Y; h = fil2.Apply(aq).Height; }
now we have to cut the pupil part from the image so we can find the image
to cut the image we use following code
System.Drawing.Bitmap Bitmapsource = (Bitmap)pictureBox1.Image; Rectangle section = new Rectangle(new Point(x - h, y - h), new< Size(3 * h, 3 *h)); Bitmap CroppedImage = CropImage(Bitmapsource, section);
the croppedimage function code is
public Bitmap CropImage(Bitmap source, Rectangle section) { Bitmap bmp = new Bitmap(section.Width, section.Height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel); return bmp;}hope that will help
Wow! that is very simple but very effective. Thanks Kishordgupta for this blog. It really helped me a lot.
thank u. glad to know that it helped
Carry on man. Hope one day this blog will be a great niche blog for c#
thank u
nice article ….i have done this after ur post
thanks
thanks
Wow… nice blog and nice works!!
Thanks Kishor for great efforts… best wishes 🙂
Thank you.
Hey I just want to let you know, I actually like the piece of writing on your website. But I am employing Flock on a machine running version 8.x of Ubuntu and the design aren’t quite right. Not a strong deal, I can still fundamentally read the articles and research for information, but just wanted to inform you about that. The navigation bar is kind of difficult to apply with the config I’m running. Keep up the superb work!
very simple and easy to understand, but the link to download sourcode?
http://www.codeproject.com/KB/dialog/Automatic_pupil_detection.aspx
u can download source code here