Exemple #1
0
        public static YiqImage FromRgb(RgbImage image)
        {
            int width  = image.Width;
            int height = image.Height;

            YiqImage result = new YiqImage(width, height);

            Matrix m = new Matrix(3, 3);

            m.Init(0.299, 0.587, 0.114, 0.596, -0.274, -0.321, 0.211, -0.526, 0.311);
            Matrix rbg = new Matrix(3, 1);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    rbg.Init(image.R[x, y], image.G[x, y], image.B[x, y]);
                    Matrix yiq = m * rbg;
                    //result.YIQ[x, y] = new YIQ(yiq[0, 0], yiq[1, 0], yiq[2, 0]);
                    result.Y[x, y]  = yiq[0, 0];
                    result.Ic[x, y] = yiq[1, 0];
                    result.Qc[x, y] = yiq[2, 0];
                }
            }

            return(result);
        }
Exemple #2
0
        public Bitmap Distorsion(double L)
        {
            double[,] result = new double[Width, Height];
            double diagonal = Math.Sqrt(Width * Width + Height * Height) / 2;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    result[x, y] = 0;
                    double u = x - Width / 2;
                    double v = y - Height / 2;
                    double r = Math.Sqrt(u * u + v * v);
                    double g = Math.Cos(r * Math.PI * L / (2 * diagonal));

                    int xi = (int)(u * g + Width / 2);
                    int yi = (int)(v * g + Height / 2);
                    result[x, y] = GetYiq().Y[xi, yi];
                }
            }

            YiqImage img = GetYiq().Clone();

            img.Y = result;

            return(img.ToBitmap());
        }
Exemple #3
0
        public Bitmap Blur(double sigma)
        {
            YiqImage yiq = GetYiq().Clone();

            yiq.Y = Blur(sigma, yiq.Y);
            return(yiq.ToBitmap());
        }
Exemple #4
0
        public static RgbImage FromYiq(YiqImage image)
        {
            int      width  = image.Width;
            int      height = image.Height;
            RgbImage result = new RgbImage(width, height);

            Matrix m = new Matrix(3, 3);

            m.Init(1, 0.956, 0.623, 1, -0.272, -0.648, 1, -1.105, 1.705);
            Matrix yiq = new Matrix(3, 1);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    yiq.Init(image.Y[x, y], image.Ic[x, y], image.Qc[x, y]);
                    Matrix rbg = m * yiq;
                    double nr  = Normalize(rbg[0, 0]);
                    double ng  = Normalize(rbg[1, 0]);
                    double nb  = Normalize(rbg[2, 0]);
                    //result.RGB[x, y] = new RGB(nr, ng, nb);
                    result.R[x, y] = nr;
                    result.G[x, y] = ng;
                    result.B[x, y] = nb;
                }
            }

            return(result);
        }
Exemple #5
0
        public Bitmap EqualizContrast()
        {
            int[]    barChart = GetYiq().GetBarChart();
            YiqImage yiq      = GetYiq().Clone();

            yiq.Y = _EqualizContrast(GetYiq().Y, barChart);
            return(yiq.ToBitmap());
        }
Exemple #6
0
        public YiqImage GetYiq()
        {
            if (yiq == null)
            {
                yiq = YiqImage.FromRgb(GetRgb());
            }

            return(yiq);
        }
Exemple #7
0
        public async Task <YiqImage> GetYiqAsync()
        {
            if (yiq == null)
            {
                yiq = await YiqImage.FromRgbAsync(await GetRgbAsync());
            }

            return(yiq);
        }
Exemple #8
0
        public async Task <Bitmap> BlurAsync(double sigma)
        {
            YiqImage yiq = await GetYiqAsync();

            var clone = yiq.Clone();

            clone.Y = Blur(sigma, yiq.Y);
            return(await clone.ToBitmapAsync());
        }
Exemple #9
0
        public YiqImage Clone()
        {
            YiqImage result = new YiqImage(this.Width, this.Height);

            result.Y  = (double[, ])Y.Clone();
            result.Ic = (double[, ])Ic.Clone();
            result.Qc = (double[, ])Qc.Clone();

            return(result);
        }
Exemple #10
0
        public static YiqImage FromBitmap(Bitmap image)
        {
            RgbImage rgb = RgbImage.FromBitmap(image);

            return(YiqImage.FromRgb(rgb));
        }
Exemple #11
0
        public static async Task <YiqImage> FromBitmapAsync(Bitmap image)
        {
            RgbImage rgb = await RgbImage.FromBitmapAsync(image);

            return(await YiqImage.FromRgbAsync(rgb));
        }
Exemple #12
0
 public static async Task <RgbImage> FromYiqAsync(YiqImage image)
 {
     return(await Task.Run(() => FromYiq(image)));
 }