:: AForge.NET Framework :: Articles :: Forums ::

C#: Detecting All Shades Of Violet

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

C#: Detecting All Shades Of Violet

Postby Andrew Eberle » Sat Jun 09, 2018 2:35 pm

G'day, I'm trying to detect if an image has any shades of Violet in it.<br><br>I made this in C# however, after some research, I came across this library and was wondering if it could help to improve what I already have?<br>
I can't seem to find any good tutorials on only colour detection, so I will just post what code I have some far and hopefully someone can help me.
Code: Select all
private bool Process(Image image)
            using (Bitmap bitmap = new Bitmap(image))
                int infected = 0;
                int total = 0;

                LockBitmap lockBitmap = new LockBitmap(bitmap);

                for (int x = 0; x != lockBitmap.Width; x++)
                    for (int y = 0; y != lockBitmap.Height; y++)
                        if (lockBitmap.GetPixel(x, y).GetHue() + 25 > Color.FromKnownColor(KnownColor.Violet).GetHue() + 20) //need to fine tune.



                if (infected > 450) //need to fine tune.
                    return true;
                    MessageBox.Show("Not Damaged");
                    return false;

Image <-- This image as far as I can tell detects the violet colour(s)<br>
Image <-- this one also detects violet shades<br>
Image <-- This one does too, which seems pretty weird because unless my eyes need checking, I cant see any violet.<br>
Image <-- This one doesn't detect any violet, which as this stage is a good thing<br><br>
What can I do to make sure that it only detects violet (any shade of violet) that we humans can see?
Thanks in advanced.
Andrew Eberle
Posts: 1
Joined: Sat Jun 09, 2018 2:28 pm

Re: C#: Detecting All Shades Of Violet

Postby andrew.kirillov » Mon Jun 11, 2018 6:57 am


Here is something about color filtering in AForge.NET Framework. HSL Filtering may help. You can also play with it in IPLab application.
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Return to AForge.NET Framework