Exemplo n.º 1
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            int y_st = (int)sizey / 2 - (_image.Height / 2) + 1;
            int y_ed = y_st + _image.Height;
            int x_ed = _image.Width + (int)_tpos;

            // Recycle deinen Puffer
            // Bild übertragen...
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    if (y >= y_st && y < y_ed && x >= _tpos && x < x_ed)
                    {
                        Rgba32 pxl = _image[x - (int)_tpos, y - y_st];
                        pbuf[x, y] = new RGBPixel(pxl.R / 255f, pxl.G / 255f, pxl.B / 255f);
                    }
                    else
                    {
                        pbuf[x, y] = RGBPixel.P0;
                    }
                }
            }

            // Text scrollen lassen und resetten
            _tpos -= this.Geschwindigkeit;
            if (_tpos + _image.Width + 6 < 0)
            {
                _tpos = _image.Width / 2;
            }
            return(Task.FromResult(pbuf));
        }
Exemplo n.º 2
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            UpdateBlasen(frame);

            // Recycle deinen Puffer
            // Male den nächsten Rahmen in das Bild.
            _image.Mutate(ctx =>
            {
                ctx.Fill(Color.Black);
                foreach (Blase b in _bl)
                {
                    var e = new EllipsePolygon(b.X, b.Y, b.R);
                    try //HACK
                    {
                        ctx.Fill(b.Fb, e);
                    }
                    catch (Exception exception)
                    {
                    }
                }
            });

            // Bild übertragen...
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    RgbaVector pxl = _image[x, y];
                    pbuf[x, y] = new RGBPixel(pxl.R, pxl.G, pxl.B);
                }
            }
            return(Task.FromResult(pbuf));
        }
Exemplo n.º 3
0
        public CustomImage <RGBPixel> YIQ2RGB(CustomImage <YIQPixel> YIQImage, bool normalize = true)
        {
            CustomImage <RGBPixel> image = new CustomImage <RGBPixel>
            {
                Width  = YIQImage.Width,
                Height = YIQImage.Height
            };

            List <RGBPixel> pixels         = new List <RGBPixel>();
            int             normalizerTerm = normalize ? 255 : 1;

            foreach (var pixel in YIQImage.Pixels)
            {
                RGBPixel Pixel = new RGBPixel()
                {
                    Xpos = pixel.Xpos,
                    Ypos = pixel.Ypos,
                    R    = ValidateRange(((pixel.Y * W_YIQ2RGB[0, 0] + pixel.I * W_YIQ2RGB[0, 1] + pixel.Q * W_YIQ2RGB[0, 2]) * normalizerTerm)),
                    G    = ValidateRange(((pixel.Y * W_YIQ2RGB[1, 0] + pixel.I * W_YIQ2RGB[1, 1] + pixel.Q * W_YIQ2RGB[1, 2]) * normalizerTerm)),
                    B    = ValidateRange(((pixel.Y * W_YIQ2RGB[2, 0] + pixel.I * W_YIQ2RGB[2, 1] + pixel.Q * W_YIQ2RGB[2, 2]) * normalizerTerm))
                };
                pixels.Add(Pixel);
            }

            image.Pixels = pixels;
            return(image);
        }
Exemplo n.º 4
0
        public Task <RGBPixel[, ]> Mix(IList <RGBPixel[, ]> sources, ulong frame)
        {
            float f0 = this.Fade.LimitTo(0f, 1f);
            float f1 = 1f - f0;

            if (sources.Count == 2)
            {
                (int x, int y) = sources[0].Dim();
                var res = new RGBPixel[x, y];
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        res[i, j] = sources[0][i, j] * f0 + sources[1][i, j] * f1;
                    }
                }
                return(Task.FromResult(res));
            }

            if (sources.Count == 1)
            {
                return(Task.FromResult(sources[0].Clone2((RGBPixel a) => a * f0)));
            }

            throw new ArgumentException("Unterstütze nicht mehr als zwei Eingaben und auch nicht 0");
        }
Exemplo n.º 5
0
        public void TestRGBPixelConverterHtmlScheitert()
        {
            RGBPixel?p1 = RGBPixel.FromHtmlColor("AABBCC");

            Assert.Null(p1);
            RGBPixel?p2 = RGBPixel.FromHtmlColor("#ABBCC");

            Assert.Null(p2);
            RGBPixel?p3 = RGBPixel.FromHtmlColor("#00AAB7BCC");

            Assert.Null(p3);
            RGBPixel?p4 = RGBPixel.FromHtmlColor("owi3zo3i5");

            Assert.Null(p4);
            RGBPixel?p5 = RGBPixel.FromHtmlColor("#owi3zo3i5");

            Assert.Null(p5);
            RGBPixel?p6 = RGBPixel.FromHtmlColor(" #abc ");

            Assert.Null(p6);
            RGBPixel?p7 = RGBPixel.FromHtmlColor(" #aabbcc ");

            Assert.Null(p7);
            RGBPixel?p8 = RGBPixel.FromHtmlColor("# abc");

            Assert.Null(p8);
            RGBPixel?p9 = RGBPixel.FromHtmlColor("");

            Assert.Null(p9);
        }
Exemplo n.º 6
0
        public void TestRGBPixelOperatorMinus()
        {
            RGBPixel a = new RGBPixel(6, 2, 3);
            RGBPixel b = a - new RGBPixel(5, 4, 3);

            Assert.Equal(1, b.R);
            Assert.Equal(-2, b.G);
            Assert.Equal(0, b.B);
        }
Exemplo n.º 7
0
        public void TestRGBPixelOperatorPlus()
        {
            RGBPixel a = new RGBPixel(6, 2, 3);
            RGBPixel b = a + new RGBPixel(5, 4, 100);

            Assert.Equal(11, b.R);
            Assert.Equal(6, b.G);
            Assert.Equal(103, b.B);
        }
Exemplo n.º 8
0
        public void TestRGBPixelOperatorMal()
        {
            RGBPixel a = new RGBPixel(1, 2, 3);
            RGBPixel b = a * new RGBPixel(5, 10, 100);

            Assert.Equal(5, b.R);
            Assert.Equal(20, b.G);
            Assert.Equal(300, b.B);
        }
Exemplo n.º 9
0
        public void TestRGBPixelOperatorSkalarDiv()
        {
            RGBPixel a = new RGBPixel(6, 36, 600);
            RGBPixel b = a / 6f;

            Assert.Equal(1, b.R);
            Assert.Equal(6, b.G);
            Assert.Equal(100, b.B);
        }
Exemplo n.º 10
0
        public void TestRGBPixelOperatorSkalar()
        {
            RGBPixel a = new RGBPixel(1, 2, 3);
            RGBPixel b = a * 5;

            Assert.Equal(5, b.R);
            Assert.Equal(10, b.G);
            Assert.Equal(15, b.B);
        }
Exemplo n.º 11
0
        public ColorCluster GetColorCluster()
        {
            LabPixel pixel = new RGBPixel(R / ClusterSize, G / ClusterSize, B / ClusterSize).ToLabPixel();

            PointF center      = new PointF((float)X / ClusterSize, (float)Y / ClusterSize);
            Point  topLeft     = new Point(MinX, MinY);
            Point  bottomRight = new Point(MaxX, MaxY);

            return(new ColorCluster(pixel, ClusterSize, center, topLeft, bottomRight));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Fill Cluster
        /// [1] After Put every Color in the min cluster
        /// [2] check if Newcendroid "cnt == NO_Clusert" if No Update Centriod and recus=rsive again
        /// [3] Do Step 1,2 untill reach the optimal cendriod
        /// </summary>
        /// <param name="cnt">Number of cluster have Down</param>
        private void Recrsive(int cnt)
        {
            if (cnt == NO_Clusert)
            {
                return;
            }

            for (int i = 0; i < li.Count; i++) // o(D) * o(C) = o(D*C)
            {
                double cost = double.MaxValue; int idx = -1;
                for (int j = 0; j < NO_Clusert; j++)
                {
                    if (calculate_cost(KmeanCluster[j][0], li[i]) < cost)
                    {
                        cost = calculate_cost(KmeanCluster[j][0], li[i]);
                        idx  = j;
                    }
                }
                KmeanCluster[idx].Add(li[i]);
                sum[idx].red   += li[i].red;
                sum[idx].green += li[i].green;
                sum[idx].blue  += li[i].blue;
            }

            for (int i = 0; i < NO_Clusert; i++) //o(Cluster)
            {
                sum[i].red   /= (KmeanCluster[i].Count - 1);
                sum[i].green /= (KmeanCluster[i].Count - 1);
                sum[i].blue  /= (KmeanCluster[i].Count - 1);
                RGBPixel col = new RGBPixel(sum[i].red, sum[i].green, sum[i].blue);
                if (KmeanCluster[i][0] == col)
                {
                    newCend.Add(new List <RGBPixel>(KmeanCluster[i])); // save if cnt == Num of cluster " Get Copy " push elemnt if eaul
                    cnt++;
                }
                KmeanCluster[i] = new List <RGBPixel>();
                KmeanCluster[i].Add(col);
                sum[i] = new MiniRGB(0, 0, 0);                       // set sum[IDX] Zero  if  repeat
            }
            if (cnt == NO_Clusert)                                   // if  cnt == CLusterNumber
            {
                KmeanCluster = new List <List <RGBPixel> >(newCend); // if equal mov newcend in actully kmean cluster
                newCend      = new List <List <RGBPixel> >();
            }
            else       // make cnt 0 and repeat
            {
                cnt     = 0;
                newCend = new List <List <RGBPixel> >(NO_Clusert);
            }

            Recrsive(cnt);  // recursive O(i) : i th Number of itertion Needs to reach mean
            // total o(DCI) : D = Disnict color ,
            // C = Number of cluster , I = Number of itertion to reach optimal mean
        }
Exemplo n.º 13
0
        private static IEnumerable <RGBPixel> GetTestPixels(Color colour, int count)
        {
            var rgbPixel = new RGBPixel
            {
                Blue  = colour.B,
                Green = colour.G,
                Red   = colour.R
            };

            return(Enumerable.Repeat(rgbPixel, count));
        }
Exemplo n.º 14
0
        public void Farbtests()
        {
            RGBPixel schwarz = RGBPixel.P0;
            RGBPixel weiß    = RGBPixel.P1;
            RGBPixel braun   = new RGBPixel(.36f, .18f, .09f);
            RGBPixel blau    = new RGBPixel(0, 0, 1);
            RGBPixel rot     = new RGBPixel(1, 0, 0);
            RGBPixel grün    = new RGBPixel(0, 1, 0);
            RGBPixel magenta = new RGBPixel(1, 0, 1);
            RGBPixel cyan    = new RGBPixel(0, 1, 1);
            RGBPixel orange  = new RGBPixel(1, .5f, 0);
            RGBPixel violett = new RGBPixel(.5f, 0, 1);
            RGBPixel zinober = new RGBPixel(1, 0.25f, 0);
            RGBPixel safran  = new RGBPixel(1, 0.75f, 0);

            HSVPixel schwarz1 = HSVPixel.P0;
            HSVPixel weiß1    = new HSVPixel(0, 0, 1);
            HSVPixel braun1   = new HSVPixel(20, 0.75f, 0.36f);
            HSVPixel blau1    = new HSVPixel(240, 1, 1);
            HSVPixel rot1     = new HSVPixel(0, 1, 1);
            HSVPixel grün1    = new HSVPixel(120, 1, 1);
            HSVPixel magenta1 = new HSVPixel(300, 1, 1);
            HSVPixel cyan1    = new HSVPixel(180, 1, 1);
            HSVPixel orange1  = new HSVPixel(30, 1, 1);
            HSVPixel violett1 = new HSVPixel(270, 1, 1);
            HSVPixel zinober1 = new HSVPixel(15, 1, 1);
            HSVPixel safran1  = new HSVPixel(45, 1, 1);

            Assert.Equal(schwarz1.V, HSVPixel.FromRGB(schwarz).V);
            Assert.Equal(schwarz, (RGBPixel)schwarz1);
            Assert.Equal(weiß1.V, HSVPixel.FromRGB(weiß).V);
            Assert.Equal(weiß1.S, HSVPixel.FromRGB(weiß).S);
            Assert.Equal(weiß, (RGBPixel)weiß1);
            Assert.Equal(braun1, HSVPixel.FromRGB(braun));
            Assert.Equal(braun, (RGBPixel)braun1);
            Assert.Equal(blau1, HSVPixel.FromRGB(blau));
            Assert.Equal(blau, (RGBPixel)blau1);
            Assert.Equal(rot1, HSVPixel.FromRGB(rot));
            Assert.Equal(rot, (RGBPixel)rot1);
            Assert.Equal(grün1, HSVPixel.FromRGB(grün));
            Assert.Equal(grün, (RGBPixel)grün1);
            Assert.Equal(magenta1, HSVPixel.FromRGB(magenta));
            Assert.Equal(magenta, (RGBPixel)magenta1);
            Assert.Equal(cyan1, HSVPixel.FromRGB(cyan));
            Assert.Equal(cyan, (RGBPixel)cyan1);
            Assert.Equal(orange1, HSVPixel.FromRGB(orange));
            Assert.Equal(orange, (RGBPixel)orange1);
            Assert.Equal(violett1, HSVPixel.FromRGB(violett));
            Assert.Equal(violett, (RGBPixel)violett1);
            Assert.Equal(zinober1, HSVPixel.FromRGB(zinober));
            Assert.Equal(zinober, (RGBPixel)zinober1);
            Assert.Equal(safran1, HSVPixel.FromRGB(safran));
            Assert.Equal(safran, (RGBPixel)safran1);
        }
Exemplo n.º 15
0
        public void TestRGBPixelOperatorUnrMinus()
        {
            RGBPixel a    = new RGBPixel(6, 2, 3);
            RGBPixel acta = -a;

            Assert.Equal(new RGBPixel(-6, -2, -3), acta);

            RGBPixel b    = new RGBPixel(-4, -22, -0.3f);
            RGBPixel actb = -b;

            Assert.Equal(new RGBPixel(4, 22, 0.3f), actb);
        }
Exemplo n.º 16
0
        public Task <RGBPixel[, ]> Filter(RGBPixel[,] pixels, ulong frame)
        {
            (int w, int h) = pixels.EnsureArray2D(ref _res);
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    _res[x, y] = RGBPixel.Max(_res[x, y] * Faktor, pixels[x, y]);
                }
            }

            return(Task.FromResult(_res));
        }
Exemplo n.º 17
0
        public void TestRGBPixelOperatorMin()
        {
            RGBPixel a   = new RGBPixel(1, 2, 3);
            RGBPixel b   = new RGBPixel(5, 10, 100);
            RGBPixel act = RGBPixel.Min(a, b);

            Assert.Equal(new RGBPixel(1, 2, 3), act);

            RGBPixel c = new RGBPixel(0.3f, 3, 0.2f);

            act = RGBPixel.Min(a, c);
            Assert.Equal(new RGBPixel(0.3f, 2, 0.2f), act);
        }
Exemplo n.º 18
0
        public Task <RGBPixel[, ]> Mix(IList <RGBPixel[, ]> sources, ulong frame)
        {
            // Schneller Ausgang
            if (sources.Count == 1)
            {
                return(Task.FromResult(sources[0]));
            }

            Func <RGBPixel, RGBPixel, RGBPixel> fn;

            switch (this.Operator)
            {
            case Operatoren.Max:
                fn = (a, b) => a = RGBPixel.Max(a, b);
                break;

            case Operatoren.Min:
                fn = (a, b) => a = RGBPixel.Min(a, b);
                break;

            case Operatoren.Add:
                fn = (a, b) => a = a + b;
                break;

            case Operatoren.Sub:
                fn = (a, b) => a = a - b;
                break;

            case Operatoren.Mul:
                fn = (a, b) => a = a * b;
                break;

            case Operatoren.Div:
                fn = (a, b) => a = a / b;
                break;

            default:
                fn = (a, b) => a;
                break;
            }

            // erstes Ding klonen.
            RGBPixel[,] res = sources[0].Clone2(o => o);
            for (int i = 1; i < sources.Count; i++)
            {
                res.MapInplace(sources[i], fn);
            }

            return(Task.FromResult(res));
        }
Exemplo n.º 19
0
        public override Task Play(RGBPixel[,] pixels)
        {
            var res = new Color[PxMap.Count];

            for (int io = 0, im = 0; im < PxMap.Count; im++)
            {
                var      koord = PxMap[im];
                RGBPixel cpx   = pixels[koord.Item1, koord.Item2];
                res[io++] = Color.FromRgb((byte)(cpx.R * 255), (byte)(cpx.G * 255), (byte)(cpx.B * 255));
            }

            this.Lcvm.FeedData(res);
            return(Task.CompletedTask);
        }
Exemplo n.º 20
0
        public void TestRGBPixelOperatorInvert()
        {
            RGBPixel a    = new RGBPixel(0.5f, 0.7f, 0.3f);
            RGBPixel acta = ~a;
            RGBPixel expa = RGBPixel.P1 - a;

            Assert.Equal(expa, acta);

            RGBPixel b    = new RGBPixel(-4, -22, -0.3f);
            RGBPixel actb = ~b;
            RGBPixel expb = RGBPixel.P1 - b;

            Assert.Equal(expb, actb);
        }
Exemplo n.º 21
0
        public Task <RGBPixel[, ]> Mix(IList <RGBPixel[, ]> sources, ulong frame)
        {
            if (sources.Count >= 2)
            {
                (int x, int y) = sources[0].Dim();
                var res = new RGBPixel[x, y];
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        int zz, zm, k;
                        if (Orientierung == Ori.Horiz)
                        {
                            zz = i;
                            zm = x - 1;
                            k  = j;
                        }
                        else
                        {
                            zz = j;
                            zm = y - 1;
                            k  = i;
                        }

                        if (zz == 0) // Rand 0
                        {
                            res[i, j] = sources[0][i, j];
                        }
                        else if (zz == zm) // Rand 1
                        {
                            res[i, j] = sources[1][i, j];
                        }
                        else // Kamm in mod2
                        {
                            res[i, j] = sources[k % 2][i, j];
                        }
                    }
                }
                return(Task.FromResult(res));
            }

            if (sources.Count == 1)
            {
                return(Task.FromResult(sources[0].Clone2((RGBPixel a) => a)));
            }

            throw new ArgumentException("Unterstütze nicht mehr als zwei Eingaben und auch nicht 0");
        }
Exemplo n.º 22
0
        public object FastEncryptionWithCompression(ref KeyValuePair <string, int> key, ref RGBPixel[,] imageSource,
                                                    ref long[,] mFrequencies)
        {
            int imageHeight = imageSource.GetLength(0),
                imageWidth  = imageSource.GetLength(1);

            Int64 shiftKey    = ConvertToInt(key.Key);
            int   tapPosition = key.Value;
            // contains the length of {0 and 1} in the key to know the last bit index
            int lastPosition = key.Key.Length;

            RGBPixel[,] targetImage = new RGBPixel[imageHeight, imageWidth];
            for (int i = 0; i < imageHeight; i++)
            {
                for (int j = 0; j < imageWidth; j++)
                {
                    if (imageSource != null)
                    {
                        byte redValue   = imageSource[i, j].Red;
                        byte greenValue = imageSource[i, j].Green;
                        byte blueValue  = imageSource[i, j].Blue;

                        // get new shifted key
                        shiftKey = FastShiftKey(shiftKey, lastPosition, tapPosition);
                        // XOR the new value of key with the color values
                        redValue ^= (byte)(shiftKey & 0xff);

                        shiftKey    = FastShiftKey(shiftKey, lastPosition, tapPosition);
                        greenValue ^= (byte)(shiftKey & 0xff);

                        shiftKey   = FastShiftKey(shiftKey, lastPosition, tapPosition);
                        blueValue ^= (byte)(shiftKey & 0xff);

                        // set the new pixel colors
                        targetImage[i, j] = new RGBPixel(redValue, greenValue, blueValue);
                        if (mFrequencies.GetLength(0) > 1)
                        {
                            mFrequencies[0, redValue]++;
                            mFrequencies[1, greenValue]++;
                            mFrequencies[2, blueValue]++;
                        }
                    }
                }
            }

            return(targetImage);
        }
Exemplo n.º 23
0
        public void ZeigeGleichheitGeht()
        {
            var a = new RGBPixel(1, 2, 3);
            var b = new RGBPixel(1.0f, 2.0f, 3.0f);

            Assert.Equal(a, b);

            var c = new RGBPixel(4, 3, 2);

            Assert.NotEqual(a, c);
            Assert.NotEqual(c, b);

            Assert.True(a == b);
            Assert.False(a == c);
            Assert.True(a != c);
            Assert.False(a != b);
        }
Exemplo n.º 24
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            using (Image <Rgba32> cloned = _resized.CloneAs <Rgba32>())
            {
                // Recycle deinen Puffer
                int k = (int)((ulong)(frame * Geschwindigkeit) % (ulong)_imgframeCount);
                for (int x = 0; x < sizex; x++)
                {
                    for (int y = 0; y < sizey; y++)
                    {
                        Rgba32 pxl = cloned.Frames[k][x, y];
                        pbuf[x, y] = new RGBPixel(pxl.R / 255f, pxl.G / 255f, pxl.B / 255f);
                    }
                }

                return(Task.FromResult(pbuf));
            }
        }
Exemplo n.º 25
0
        public void TestRGBPixelConverterHtml()
        {
            RGBPixel?p1 = RGBPixel.FromHtmlColor("#FB5");

            Assert.NotNull(p1); //[1/0,7333333/0,3333333]
            Assert.NotEqual(p1.Value.R, p1.Value.B);
            Assert.NotEqual(p1.Value.R, p1.Value.G);
            Assert.NotEqual(p1.Value.B, p1.Value.G);
            Assert.Equal(p1, new RGBPixel(1f, 0.73333333333f, .33333333333f));

            RGBPixel?p2 = RGBPixel.FromHtmlColor("#AABBCC");

            Assert.NotNull(p2);

            RGBPixel?p3 = RGBPixel.FromHtmlColor("#33FF55cc");

            Assert.NotNull(p3);

            RGBPixel?p4 = RGBPixel.FromHtmlColor("#444c");

            Assert.NotNull(p4);

            RGBPixel?p5 = RGBPixel.FromHtmlColor("#222");

            Assert.NotNull(p5);

            RGBPixel?p6 = RGBPixel.FromHtmlColor("#c040d0");

            Assert.NotNull(p6);


            //Assert.Equal(p.Value.R, 3);
            // Gleichheit von #DDD mit #DDDDDD !!
            // und gleich #444 zu #444444
            RGBPixel?g1 = RGBPixel.FromHtmlColor("#DDD");
            RGBPixel?g2 = RGBPixel.FromHtmlColor("#DDDDDD");

            Assert.Equal(g1, g2);
            RGBPixel?h1 = RGBPixel.FromHtmlColor("#4444");
            RGBPixel?h2 = RGBPixel.FromHtmlColor("#cc444444");

            Assert.Equal(h1, h2);
        }
Exemplo n.º 26
0
        public void TestRGBPixelOperatorClip()
        {
            RGBPixel a    = new RGBPixel(0.5f, 0.7f, 0.3f);
            RGBPixel acta = a.Clip();
            RGBPixel expa = a;

            Assert.Equal(expa, acta);

            RGBPixel b    = new RGBPixel(1.3f, 10.9f, 1.443f);
            RGBPixel actb = b.Clip();
            RGBPixel expb = new RGBPixel(1, 1, 1);

            Assert.Equal(expb, actb);

            RGBPixel c    = new RGBPixel(-4, -22, -0.3f);
            RGBPixel actc = c.Clip();
            RGBPixel expc = new RGBPixel(0, 0, 0);

            Assert.Equal(expc, actc);
        }
        /// <summary>
        /// [1] Loop to Number of Cluster
        /// [2] In every itertion go to loop in Cubic and splites all cubic
        /// [3] After return Change in 3D RJB volors Values
        /// </summary>
        public override void getcluster()
        {
            for (int i = 0; i < NO_Clusert; i++) //o(2 || 4 || 8 || 16 ||....||2042 ) =o(1)*NlogN
            {
                if (CubesList.Count == NO_Clusert)
                {
                    break;
                }
                SplitBigCubes();                     // o(NlogN)
            }
            foreach (MedianCutHelper Q in CubesList) // o(Cluster*cluster.size)~= o(1)*o(D)=o(D)
            {
                RGBPixel res = Q.Averge;
                this.Pallete.Add(res);

                for (int i = 0; i < Q.colorList.Count; i++)
                {
                    RGB[Q.colorList[i].red, Q.colorList[i].green, Q.colorList[i].blue]
                        = new RGBPixel(res.red, res.green, res.blue);
                }
            }
        }
Exemplo n.º 28
0
        public List <ColorCluster> GetClustersSortedByMostWhite()
        {
            LabPixel whitePixel = new RGBPixel(255, 255, 255).ToLabPixel();

            return(clusters.OrderBy(x => whitePixel.DistanceCIE94IgnoreIllumination(x.ClusterColor)).ToList());
        }
Exemplo n.º 29
0
 /// <summary>
 /// Take To RGPPIXEL ANd Get Distance Between Theem
 /// </summary>
 /// <param name="i"> First RGBPixel</param>
 /// <param name="j">Second RGBPixel</param>
 /// <returns></returns>
 public double calculate_cost(RGBPixel i, RGBPixel j)
 {
     return(Math.Sqrt((i.red - j.red) * (i.red - j.red) +
                      (i.green - j.green) * (i.green - j.green) +
                      (i.blue - j.blue) * (i.blue - j.blue)));
 }
Exemplo n.º 30
0
        public object OpenImage(string imagePath)
        {
            Bitmap originalBm = new Bitmap(imagePath);
            int    height     = originalBm.Height;
            int    width      = originalBm.Width;

            RGBPixel[,] buffer = new RGBPixel[height, width];

            unsafe
            {
                BitmapData bmd = originalBm.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite,
                                                     originalBm.PixelFormat);
                int  x, y;
                int  nWidth   = 0;
                bool format32 = false;
                bool format24 = false;
                bool format8  = false;

                if (originalBm.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    format24 = true;
                    nWidth   = width * 3;
                }
                else if (originalBm.PixelFormat == PixelFormat.Format32bppArgb ||
                         originalBm.PixelFormat == PixelFormat.Format32bppRgb ||
                         originalBm.PixelFormat == PixelFormat.Format32bppPArgb)
                {
                    format32 = true;
                    nWidth   = width * 4;
                }
                else if (originalBm.PixelFormat == PixelFormat.Format8bppIndexed)
                {
                    format8 = true;
                    nWidth  = width;
                }

                int   nOffset = bmd.Stride - nWidth;
                byte *p       = (byte *)bmd.Scan0;
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        buffer[y, x] = new RGBPixel();
                        if (format8)
                        {
                            buffer[y, x].Red = buffer[y, x].Green = buffer[y, x].Blue = p[0];
                            p++;
                        }
                        else
                        {
                            buffer[y, x].Red   = p[2];
                            buffer[y, x].Green = p[1];
                            buffer[y, x].Blue  = p[0];
                            if (format24)
                            {
                                p += 3;
                            }
                            else if (format32)
                            {
                                p += 4;
                            }
                        }
                    }

                    p += nOffset;
                }

                originalBm.UnlockBits(bmd);
            }

            return(buffer);
        }