-1

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.

Ahmad Afkandeh
  • 107
  • 1
  • 10
  • 2
    You may be interested in [this discussion of color distance](http://stackoverflow.com/questions/27374550/how-to-compare-color-object-and-get-closest-color-in-an-color/27375621?s=1|1.0460#27375621) – TaW Jan 21 '17 at 13:58
  • "My final goal is to find out color is changed to a specific color or not": then you just do if hsb.hue=thisparticularcolor.hue fire event; you dont need the discussion it will confuse you more – gpasch Jan 21 '17 at 21:49
  • @gpasch you are right, but for example the red color has a variety of values. and I have a area which is dark red, and I want to know if it became to lighter red or not, or even it is black and it becomes red or green or yellow. So I don't think this is easy as you said. – Ahmad Afkandeh Jan 22 '17 at 07:33
  • @TaW It looks interesting, thanks. I tell you if it solved my problem. – Ahmad Afkandeh Jan 22 '17 at 07:33
  • @TaW I got a little confused, what if I want to compare first HSB with second HSB and get the similarity? – Ahmad Afkandeh Jan 22 '17 at 10:19
  • Well, this is not clearly defined; it is up to you to weigh the importance the numbers have for you. Make sure the hue is scaled to the same range as S and B, usually 0..1. The simplest gauge would be the sum of the abs of the 3 deltas; here you still need to take the wrap-around of the hue into account !! - . But maybe saturation is a little less importants than brightness?.. Also: Not all ranges in the color space may be perceived the same to the human eye..See [here for a dicussion of this](http://stackoverflow.com/questions/31612232/color-table-algorithm/31626758?s=1|0.0431#31626758) – TaW Jan 22 '17 at 10:33

1 Answers1

0

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

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

Ahmad Afkandeh
  • 107
  • 1
  • 10