Page 1 of 1

C#: Detecting All Shades Of Violet

PostPosted: Sat Jun 09, 2018 2:35 pm
by Andrew Eberle
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.

Re: C#: Detecting All Shades Of Violet

PostPosted: Mon Jun 11, 2018 6:57 am
by andrew.kirillov

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