Exemple #1
0
        void eStep(Config config)
        {
            double[] sum_w = new double[config.wi * config.hi];

            For.AllKernels(config, (_, k) =>
            {
                double sum = 0;
                For.AllPixelsOfRegion(config, k, (_1, i) =>
                {
                    int idx = index(config, i, k);
                    System.Diagnostics.Debug.Assert(idx >= 0);
                    System.Diagnostics.Debug.Assert(idx < w(k).Length);
                    w(k)[index(config, i, k)] = calcGaussian(k, i);
                    sum += w(k)[index(config, i, k)];
                });

                For.AllPixelsOfRegion(config, k, (_1, i) =>
                {
                    w(k)[index(config, i, k)] = div(w(k)[index(config, i, k)], sum);
                    sum_w[i.index]           += w(k)[index(config, i, k)];
                });
            });

            For.AllPixels(config, (_, i) =>
            {
                For.AllKernelOfPixel(config, i, (_1, k) =>
                {
                    g(k)[index(config, i, k)] = div(w(k)[index(config, i, k)], sum_w[i.index]);
                });
            });
        }
Exemple #2
0
        Vec3 sumInRegion(Config config, Kernel k, Func <Position, Vec3> pos2val)
        {
            var result = new Vec3(0, 0, 0);

            For.AllPixelsOfRegion(config, k, (_, i) =>
            {
                result += pos2val(i);
            });
            return(result);
        }
Exemple #3
0
        double sumInRegion(Config config, Kernel k, Func <Position, double> pos2val)
        {
            double result = 0;

            For.AllPixelsOfRegion(config, k, (_, i) =>
            {
                result += pos2val(i);
            });
            return(result);
        }
Exemple #4
0
        // return image whose size is [config.wo, config.ho].
        public unsafe Bitmap CreateOutputImage(Config config)
        {
            var bmp = new Bitmap(config.wo, config.ho, PixelFormat.Format32bppArgb);

            using (var it = new FLib.BitmapIterator(bmp, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb))
            {
                byte *data = it.Data;

                For.AllKernels(config, (_, k) =>
                {
                    List <Vec3> debug = new List <Vec3>();

                    Vec3 sumColor    = new Vec3(0, 0, 0);
                    double sumWeight = 0;
                    int count        = 0;
                    For.AllPixelsOfRegion(config, k, (_0, i) =>
                    {
                        double weight = w(k)[index(config, i, k)];
                        int x         = (int)(i.p.x + m[k.index].x - k.xi - (int)(1.5 * config.rx));
                        int y         = (int)(i.p.y + m[k.index].y - k.yi - (int)(1.5 * config.rx));
                        if (x < 0 || config.wi <= x || y < 0 || config.hi <= y)
                        {
                            return;
                        }
                        int idx    = x + y * config.wi;
                        sumColor  += weight * c[idx];
                        sumWeight += weight;
                        count++;
                        debug.Add(weight * c[idx]);
                    });

                    Vec3 aveColor = sumColor / sumWeight;
                    System.Diagnostics.Debug.Assert(0 <= aveColor.x && aveColor.x <= 1);
                    System.Diagnostics.Debug.Assert(0 <= aveColor.y && aveColor.y <= 1);
                    System.Diagnostics.Debug.Assert(0 <= aveColor.z && aveColor.z <= 1);
                    byte r = (byte)(255 * aveColor.x);
                    byte g = (byte)(255 * aveColor.y);
                    byte b = (byte)(255 * aveColor.z);
                    data[4 * k.x + k.y * it.Stride + 0] = b;
                    data[4 * k.x + k.y * it.Stride + 1] = g;
                    data[4 * k.x + k.y * it.Stride + 2] = r;
                    data[4 * k.x + k.y * it.Stride + 3] = 255;
                });
            }
            return(bmp);
        }