Пример #1
0
        public RgbImage ToRgbImage()
        {
            var res = new RgbImage(PixelWidth, PixelHeight);

            ForEach((pixel, position) => res[position] = pixel.ToRgb());
            return(res);
        }
Пример #2
0
        public RgbImage PixelParallelMap(PixelPositionPipelineDelegate process)
        {
            var res = new RgbImage(PixelWidth, PixelHeight);

            PixelParallelForEach((pixel, position) => res[position] = process(pixel, position));
            return(res);
        }
Пример #3
0
        private RgbImage ScaleWithBilinearInterpolation(double kx, double ky)
        {
            var res = new RgbImage((PixelWidth * kx).Round(), (PixelHeight * ky).Round());

            for (int x = 0; x < PixelWidth - 1; x++)
            {
                for (int y = 0; y < PixelHeight - 1; y++)
                {
                    int      nx1 = (kx * x).Round(), ny1 = (ky * y).Round();
                    int      nx2 = (kx * (x + 1)).Round(), ny2 = (ky * (y + 1)).Round();
                    RgbPixel p11 = this[x, y].Value,
                             p12 = this[x, y + 1].Value,
                             p21 = this[x + 1, y].Value,
                             p22 = this[x + 1, y + 1].Value;
                    for (int nx = nx1; nx <= nx2; nx++)
                    {
                        for (int ny = ny1; ny <= ny2; ny++)
                        {
                            double k = (nx2 - nx1) * (ny2 - ny1);
                            double m1 = nx2 - nx, m2 = nx - nx1;
                            double n1 = ny2 - ny, n2 = ny - ny1;
                            res[nx, ny] = m2 * n2 / k * p11 + m1 * n2 / k * p21 + m2 * n1 / k * p12 + m1 * n1 / k * p22;
                        }
                    }
                }
            }

            return(res);
        }
Пример #4
0
        public RgbImage Transform(int newWidth, int newHeight, TransformDelegate transform)
        {
            var res = new RgbImage(newWidth, newHeight);

            for (int y = 0; y < PixelHeight; y++)
            {
                for (int x = 0; x < PixelWidth; x++)
                {
                    var newPos = transform(new Point(x, y));
                    if (newPos.X < 0 || newPos.X >= newWidth)
                    {
                        continue;
                    }
                    if (newPos.Y < 0 || newPos.Y >= newHeight)
                    {
                        continue;
                    }
                    res[newPos] = this[x, y];
                }
            }

            return(res);
        }
Пример #5
0
 private void NearestNeighborInterpolation(RgbImage origin, double kx, double ky)
 {
     for (int x = 0; x < PixelWidth; x++)
     {
         for (int y = 0; y < PixelHeight; y++)
         {
             if (this[x, y] != null)
             {
                 continue;
             }
             int x0 = (int)Math.Round(x / kx);
             if (x0 < 0 || x0 >= origin.PixelWidth)
             {
                 continue;
             }
             int y0 = (int)Math.Round(y / ky);
             if (y0 < 0 || y0 >= origin.PixelHeight)
             {
                 continue;
             }
             this[x, y] = origin[x0, y0];
         }
     }
 }