Ejemplo n.º 1
0
        // RGB2YIQ
        public CustomImage <YIQPixel> RGB2YIQ(Color[][] RGBImage, bool normalize = true)
        {
            CustomImage <YIQPixel> image = new CustomImage <YIQPixel>
            {
                Width  = RGBImage[0].Length,
                Height = RGBImage[1].Length
            };

            List <YIQPixel> pixels = new List <YIQPixel>();

            for (int i = 0; i < RGBImage[0].Length; i++)
            {
                for (int j = 0; j < RGBImage[1].Length; j++)
                {
                    // Normalize each pixel value
                    float NR, NG, NB;
                    NR = normalize ? RGBImage[i][j].R / 255.00F : RGBImage[i][j].R;
                    NG = normalize ? RGBImage[i][j].G / 255.00F : RGBImage[i][j].G;
                    NB = normalize ? RGBImage[i][j].B / 255.00F : RGBImage[i][j].B;

                    YIQPixel Pixel = new YIQPixel()
                    {
                        Xpos = i,
                        Ypos = j,
                        Y    = NR * W_RGB2YIQ[0, 0] + NG * W_RGB2YIQ[0, 1] + NB * W_RGB2YIQ[0, 2],
                        I    = NR * W_RGB2YIQ[1, 0] + NG * W_RGB2YIQ[1, 1] + NB * W_RGB2YIQ[1, 2],
                        Q    = NR * W_RGB2YIQ[2, 0] + NG * W_RGB2YIQ[2, 1] + NB * W_RGB2YIQ[2, 2]
                    };
                    pixels.Add(Pixel);
                }
            }

            image.Pixels = pixels;
            return(image);
        }
Ejemplo n.º 2
0
        public CustomImage <RGBPixel> LumaChrominance(CustomImage <YIQPixel> YIQImage, float alpha = 1.0F, float beta = 1.0F)
        {
            CustomImage <YIQPixel> result = new CustomImage <YIQPixel>
            {
                Width  = YIQImage.Width,
                Height = YIQImage.Height
            };

            List <YIQPixel> pixels = new List <YIQPixel>();

            foreach (var pixel in YIQImage.Pixels)
            {
                YIQPixel YIQModPixel = new YIQPixel
                {
                    Xpos = pixel.Xpos,
                    Ypos = pixel.Ypos,
                    Y    = ValidateYIQ(pixel.Y * alpha, 0F, 1F),
                    I    = ValidateYIQ(pixel.I * beta, -0.5957F, 0.5957F),
                    Q    = ValidateYIQ(pixel.Q * beta, -0.5226F, 0.5226F)
                };
                pixels.Add(YIQModPixel);
            }

            result.Pixels = pixels;
            return(YIQ2RGB(result));
        }
Ejemplo n.º 3
0
        public CustomImage <RGBPixel> LumaFilter(CustomImage <YIQPixel> YIQImage, string filter, float min = 0.2F, float max = 0.8F)
        {
            CustomImage <YIQPixel> result = new CustomImage <YIQPixel>
            {
                Width  = YIQImage.Width,
                Height = YIQImage.Height
            };

            List <YIQPixel> pixels = new List <YIQPixel>();

            foreach (var pixel in YIQImage.Pixels)
            {
                YIQPixel YIQModPixel = new YIQPixel
                {
                    Xpos = pixel.Xpos,
                    Ypos = pixel.Ypos,
                    I    = ValidateYIQ(pixel.I, -0.5957F, 0.5957F),
                    Q    = ValidateYIQ(pixel.Q, -0.5226F, 0.5226F)
                };

                switch (filter)
                {
                case "Raíz":
                    YIQModPixel.Y = ValidateYIQ((float)Math.Sqrt(pixel.Y), 0, 1);
                    break;

                case "Cuadrado":
                    YIQModPixel.Y = ValidateYIQ((float)Math.Pow(pixel.Y, 2), 0, 1);
                    break;

                case "Lineal a trozos":
                    float n = min / (1 - min);
                    float m = (1 + n) * max;
                    float Y = m * pixel.Y - n;
                    YIQModPixel.Y = ValidateYIQ(Y, 0, 1);
                    break;
                }

                pixels.Add(YIQModPixel);
            }

            result.Pixels = pixels;
            return(YIQ2RGB(result));
        }