Esempio n. 1
0
        private void PopulateTree(double hue, double saturation, double value, int frequency)
        {
            if (subTreesHue.Exists(bt => bt.Magnitude == hue))
            {
                int indexHue = subTreesHue.FindIndex(bt => bt.Magnitude == hue);

                // next find if the specific green exists in a subtree of blue
                // such that Gn | Bn

                if (subTreesHue[indexHue].subTreesSaturation.
                    Exists(gt => gt.Magnitude == saturation))
                {
                    int      indexSat = subTreesHue[indexHue].subTreesSaturation.FindIndex(gt => gt.Magnitude == saturation);
                    ValueFIP valueFIP = new ValueFIP();
                    valueFIP.Magnitude = value;
                    valueFIP.Frequency = frequency;
                    subTreesHue[indexHue].subTreesSaturation[indexSat].valueNodes.Add(valueFIP);
                }
                else
                {
                    SatTree st = new SatTree();
                    st.Magnitude = saturation;
                    ValueFIP valueFIP = new ValueFIP();
                    valueFIP.Magnitude = value;
                    valueFIP.Frequency = frequency;

                    st.valueNodes.Add(valueFIP);
                    subTreesHue[indexHue].subTreesSaturation.Add(st);
                }
            }
            else
            {
                HueTree  ht       = new HueTree();
                SatTree  st       = new SatTree();
                ValueFIP valueFIP = new ValueFIP();

                valueFIP.Magnitude = value;
                valueFIP.Frequency = frequency;

                st.Magnitude = saturation;
                ht.Magnitude = hue;

                st.valueNodes.Add(valueFIP);
                ht.subTreesSaturation.Add(st);
                subTreesHue.Add(ht);
            }
        }
Esempio n. 2
0
        public double GetProb(Hsv hsv)
        {
            double result     = 0.0;
            double hue        = BringDown(hsv.Hue, DIVISOR);
            double saturation = BringDown(hsv.Satuation, DIVISOR);
            double value      = BringDown(hsv.Value, DIVISOR);

            int blueIndex = BinSearchHue(hue);

            if (blueIndex < 0)
            {
                return(result);
            }
            else
            {
                int greenIndex = BinSearchSaturation(blueIndex, saturation);

                if (greenIndex < 0)
                {
                    return(result);
                }
                else
                {
                    ValueFIP valueFIP = subTreesHue[blueIndex].
                                        subTreesSaturation[greenIndex].
                                        valueNodes.Find(prfi => prfi.Magnitude == value);

                    if (valueFIP == null)
                    {
                        return(result);
                    }
                    else
                    {
                        return(valueFIP.Probabilty);
                    }
                }
            }
        }
Esempio n. 3
0
        public int GetFreq(Hsv hsv)
        {
            int    result     = 0;
            double hue        = BringDown(hsv.Hue, DIVISOR);
            double saturation = BringDown(hsv.Satuation, DIVISOR);
            double value      = BringDown(hsv.Value, DIVISOR);

            int hueIndex = BinSearchHue(hue);

            if (hueIndex < 0)
            {
                return(result);
            }
            else
            {
                int saturationIndex = BinSearchSaturation(hueIndex, saturation);

                if (saturationIndex < 0)
                {
                    return(result);
                }
                else
                {
                    ValueFIP valueFIP = subTreesHue[hueIndex].
                                        subTreesSaturation[saturationIndex].
                                        valueNodes.Find(prfi => prfi.Magnitude == value);

                    if (valueFIP == null)
                    {
                        return(result);
                    }
                    else
                    {
                        return(valueFIP.Frequency);
                    }
                }
            }
        }