Exemplo n.º 1
0
        private static SourceImage GetIntensityMap(SourceImage sourceImage, int workerMin, int range)
        {
            var newSourceImage = new SourceImage();

            newSourceImage.Height = sourceImage.Height;
            newSourceImage.Width  = sourceImage.Width;
            newSourceImage.Pixels = new Pixel[newSourceImage.Width * newSourceImage.Height];
            for (int y = 0; y < sourceImage.Height; y++)
            {
                for (int x = 0; x < sourceImage.Width; x++)
                {
                    Color c         = sourceImage.GetPixel(x, y);
                    var   intensity = (int)(c.GetBrightness() * 255);

                    if (intensity >= workerMin && intensity <= workerMin + range)
                    {
                        newSourceImage.SetPixel(x, y, c);
                    }
                    else
                    {
                        newSourceImage.SetPixel(x, y, Color.Black);
                    }
                }
            }

            return(newSourceImage);
        }
Exemplo n.º 2
0
        public override void ProcessPixels(RectangleI region)
        {
            ComplexGrid gridDirect  = new ComplexGrid(ImageBounds, ProjectionBounds, fDir);
            ComplexGrid gridInverse = new ComplexGrid(ImageBounds, ProjectionBounds, fInv);

            Parallel.For(region.TopLeft.Y, region.BottomRight.Y, y =>
            {
                Parallel.For(region.TopLeft.X, region.BottomRight.X, x =>
                {
                    var pDir = (PointI)lerpPoint(new PointD(x, y), gridDirect[x, y], Alpha);
                    var pInv = (PointI)lerpPoint(new PointD(x, y), gridInverse[x, y], Alpha);
                    SKColor color;
                    if (IsPointInRange(pDir, ImageBounds))
                    {
                        color = SourceImage.GetPixel(pDir.X, pDir.Y);
                    }
                    else if (IsPointInRange(pInv, ImageBounds))
                    {
                        color = SourceImage.GetPixel(pInv.X, pInv.Y);
                    }
                    else
                    {
                        color = SKColor.Empty;
                    }
                    DestImage.SetPixel(x, y, color);
                });
            });
        }
Exemplo n.º 3
0
 public Color ReadPixel(Point p)
 {
     if (IsReady)
     {
         if (p.X >= 0 && p.Y >= 0 && p.X < SourceImage.Width && p.Y < sourceImage.Height)
         {
             return(SourceImage.GetPixel(p.X, p.Y));
         }
     }
     return(Color.Empty);
 }
Exemplo n.º 4
0
 public Bitmap RGBtoGrey()
 {
     GreyImage = new Bitmap(SourceImage.Width, SourceImage.Height);
     yuvImage  = new YUV[SourceImage.Width, SourceImage.Height];
     for (int x = 0; x < GreyImage.Width; ++x)
     {
         for (int y = 0; y < GreyImage.Height; ++y)
         {
             var    t = SourceImage.GetPixel(x, y);
             double c = 0.2126 * t.R + 0.7152 * t.G + 0.0722 * t.B;
             ++IntensitySource[(int)c];
             GreyImage.SetPixel(x, y, Color.FromArgb((int)c, (int)c, (int)c));
             yuvImage[x, y] = new YUV(c, t);
         }
     }
     return(GreyImage);
 }
Exemplo n.º 5
0
        public override void ProcessPixels(RectangleI region)
        {
            Api api = new Api(
                image: new Image(SourceImage),
                param: new ScriptParams(
                    PrimaryParam,
                    SecondaryParam,
                    (Pixel)ColorParam
                    )
                );

            Parallel.For(region.TopLeft.Y, region.BottomRight.Y, (y, outer) =>
            {
                if (EncounteredError)
                {
                    outer.Break();
                    return;
                }
                Parallel.For(region.TopLeft.X, region.BottomRight.X, (x, inner) =>
                {
                    if (EncounteredError)
                    {
                        inner.Break();
                        return;
                    }
                    try
                    {
                        SKColor src    = SourceImage.GetPixel(x, y);
                        Pixel colorIn  = new Pixel(src.Blue, src.Green, src.Red, src.Alpha);
                        Pixel colorOut = FilterFunc(api, colorIn, x, y);
                        SKColor dst    = new SKColor(colorOut.Blue, colorOut.Green, colorOut.Red, colorOut.Alpha);
                        DestImage.SetPixel(x, y, dst);
                    }
                    catch (Exception e)
                    {
                        if (!EncounteredError)
                        {
                            EncounteredError = true;
                            MessageBox.Show($"Your code encountered an exception at runtime.\n{e.Message}",
                                            "Runtime Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                });
            });
        }
Exemplo n.º 6
0
        public Bitmap Transform()
        {
            Bitmap result = new Bitmap(SourceImage.Width, SourceImage.Height);

            for (int x = 0; x < result.Width; ++x)
            {
                for (int y = 0; y < result.Height; ++y)
                {
                    Color source  = SourceImage.GetPixel(x, y);
                    Color replace = Color.FromArgb(
                        Common.Clip(source.R * (ColorDestination.R / ColorSource.R)),
                        Common.Clip(source.G * (ColorDestination.G / ColorSource.G)),
                        Common.Clip(source.B * (ColorDestination.B / ColorSource.B)));
                    result.SetPixel(x, y, replace);
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public Bitmap Transform()
        {
            Bitmap result = new Bitmap(SourceImage.Width, SourceImage.Height);
            var    cntPix = SourceImage.Width * SourceImage.Height; //N
            int    r      = 0;
            int    g      = 0;
            int    b      = 0;

            for (int x = 0; x < SourceImage.Width; ++x)
            {
                for (int y = 0; y < SourceImage.Height; ++y)
                {
                    var t = SourceImage.GetPixel(x, y);
                    r += t.R;
                    g += t.G;
                    b += t.B;
                }
            }
            r /= cntPix;  //Можно сократить, используя арифметику,
            g /= cntPix;  //но теряется понимание формулы
            b /= cntPix;

            var avg = (r + b + g) / 3;

            for (int x = 0; x < SourceImage.Width; ++x)
            {
                for (int y = 0; y < SourceImage.Height; ++y)
                {
                    var t = SourceImage.GetPixel(x, y);
                    result.SetPixel(x, y, Color.FromArgb(t.A,
                                                         Common.Clip(t.R * avg / r),
                                                         Common.Clip(t.G * avg / g),
                                                         Common.Clip(t.B * avg / b)));
                }
            }
            return(result);
        }