Beispiel #1
0
        public int Count(bool force)
        {
            if (count == null || force)
            {
                var npix = 0;
                int i;

                for (i = R1; i <= R2; i++)
                {
                    int j;
                    for (j = G1; j <= G2; j++)
                    {
                        int k;
                        for (k = B1; k <= B2; k++)
                        {
                            var index = Mmcq.GetColorIndex(i, j, k);
                            npix += histo[index];
                        }
                    }
                }

                count = npix;
            }

            return(count.Value);
        }
Beispiel #2
0
        public int[] Avg(bool force)
        {
            if (avg == null || force)
            {
                var ntot = 0;

                var rsum = 0;
                var gsum = 0;
                var bsum = 0;

                int i;

                for (i = R1; i <= R2; i++)
                {
                    int j;
                    for (j = G1; j <= G2; j++)
                    {
                        int k;
                        for (k = B1; k <= B2; k++)
                        {
                            var histoindex = Mmcq.GetColorIndex(i, j, k);
                            var hval       = histo[histoindex];
                            ntot += hval;
                            rsum += Convert.ToInt32((hval * (i + 0.5) * Mmcq.Mult));
                            gsum += Convert.ToInt32((hval * (j + 0.5) * Mmcq.Mult));
                            bsum += Convert.ToInt32((hval * (k + 0.5) * Mmcq.Mult));
                        }
                    }
                }

                if (ntot > 0)
                {
                    avg = new[]
                    {
                        Math.Abs(rsum / ntot), Math.Abs(gsum / ntot),
                        Math.Abs(bsum / ntot)
                    };
                }
                else
                {
                    avg = new[]
                    {
                        Math.Abs(Mmcq.Mult * (R1 + R2 + 1) / 2),
                        Math.Abs(Mmcq.Mult * (G1 + G2 + 1) / 2),
                        Math.Abs(Mmcq.Mult * (B1 + B2 + 1) / 2)
                    };
                }
            }

            return(avg);
        }