Example #1
0
        private static Bitmap NewColor(Bitmap source, Bitmap insert, Rectangle r)
        {
            List <Vector> srV = new List <Vector>();
            List <Vector> inV = new List <Vector>();;


            for (int i = r.X; i < r.X + r.Width - 2; i += 3)
            {
                for (int j = r.Y; j < r.Y + r.Height - 3; j += 4)
                {
                    Color color  = source.GetPixel(i, j);
                    Color color2 = insert.GetPixel(i, j);
                    srV.Add(new double[] { color.R, color.G, color.B }.ToVector());
                    inV.Add(new double[] { color2.R, color2.G, color2.B }.ToVector());
                }
            }

            Vector meanSrc = Vector.Mean(srV.ToArray()) / 255;
            Vector meanInk = Vector.Mean(inV.ToArray()) / 255;

            Tensor tensor = ImgConverter.BmpToTensor(insert.Clone(r, PixelFormat.Format32bppArgb));


            tensor = tensor.DivD(meanInk);
            tensor = tensor.PlusD(meanSrc);

            tensor = tensor.TransformTensor(x =>
            {
                if (x < 0)
                {
                    x = 0;
                }
                if (x > 1)
                {
                    x = 1;
                }
                return(x);
            });

            return(ImgConverter.TensorToBitmap(tensor));
        }