Comparing two HSB colors

445 views Asked by At

I have a project which captures an area and find it's Dominant color in HSB, I used this article to find the dominant color.

In my code I get the dominant color at startup of my project, and every second I take a picture of that area and compare it with the first color with this code:

private bool IsColorChanged(Structures.HSB hsb)
    {
        //hsb is the newest dominant color of that area
        //m_refcolor is the main color of that area which I got at startup
        Structures.HSB localhsb;
            localhsb.Hue = Math.Abs(hsb.Hue - m_refcolor.Hue);
            localhsb.Saturation = Math.Abs(hsb.Saturation - m_refcolor.Saturation);
            localhsb.Brightness = Math.Abs(hsb.Brightness - m_refcolor.Brightness);
            if ((localhsb.Hue >= m_hsbtr.Htreshold) || (localhsb.Saturation >= m_hsbtr.Streshold) || (localhsb.Brightness >= m_hsbtr.Btreshold))
                return true;
        return false;
    }

If the color was changed to anycolor I fire an Event to the user.

My final goal is to find out color is changed to a specific color or not? but I don't know what should I do. I mean I don't know how to compare to HSB with each other, the code I used only works if I want to know if the color changed to any color.

I used c# but I don't have problem with other languages. Any help would be awesome.

1

There are 1 answers

0
Ahmad Afkande On

My problem solved using ColorMine project, without any more coding.

This projects uses Delta-E to compare colors and supports many color spaces.