Exemple #1
0
        public unsafe ImageRgb24 ToImageRgb24WithRamdomColorMap()
        {
            ImageRgb24 img              = new ImageRgb24(this.Width, this.Height);
            Random     r                = new Random();
            int        length           = this.Length;
            Dictionary <int, Rgb24> map = new Dictionary <int, Rgb24>();

            for (int i = 0; i < length; i++)
            {
                int val = this[i];
                if (map.ContainsKey(val))
                {
                    img[i] = map[val];
                }
                else
                {
                    Rgb24 newRgb = new Rgb24();
                    newRgb.Red   = (byte)(r.Next(256));
                    newRgb.Green = (byte)(r.Next(256));
                    newRgb.Blue  = (byte)(r.Next(256));
                    img[i]       = newRgb;
                    map.Add(val, newRgb);
                }
            }
            return(img);
        }
Exemple #2
0
        public override IImage Clone()
        {
            ImageRgb24 img = new ImageRgb24(this.Width, this.Height);

            img.CloneFrom(this);
            return(img);
        }
Exemple #3
0
        public unsafe ImageRgb24 ToImageRgb24()
        {
            ImageRgb24 img = new ImageRgb24(this.Width, this.Height);

            UnmanagedImageConverter.ToRgb24((Lab24 *)this.StartIntPtr, img.Start, img.Length);
            return(img);
        }
Exemple #4
0
        public unsafe ImageLab24(ImageRgb24 img)
            : base(img.Width, img.Height)
        {
            int length = img.Length;

            UnmanagedImageConverter.ToLab24(img.Start, (Lab24 *)this.StartIntPtr, length);
        }
Exemple #5
0
        public unsafe void ApplyMedianFilter(int medianRadius)
        {
            if (medianRadius > 0)
            {
                // 进行中值滤波
                using (ImageRgb24 copy = this.Clone() as ImageRgb24)
                {
                    int    size   = medianRadius * 2 + 1;
                    int    count  = 0;
                    byte[] r      = new byte[size * size];
                    byte[] g      = new byte[size * size];
                    byte[] b      = new byte[size * size];
                    int    height = this.Height;
                    int    width  = this.Width;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            count = 0;
                            for (int h = -medianRadius; h <= medianRadius; h++)
                            {
                                for (int w = -medianRadius; w <= medianRadius; w++)
                                {
                                    int hh = y + h;
                                    int ww = x + w;
                                    if (hh >= 0 && hh < height && ww >= 0 && ww < width)
                                    {
                                        Rgb24 c = copy[hh, ww];
                                        r[count] = c.Red;
                                        g[count] = c.Green;
                                        b[count] = c.Blue;
                                        count++;
                                    }
                                }
                            }

                            Array.Sort(r, 0, count);
                            Array.Sort(g, 0, count);
                            Array.Sort(b, 0, count);
                            int   m      = count >> 1;
                            Rgb24 median = new Rgb24 {
                                Red = r[m], Green = g[m], Blue = b[m]
                            };
                            this[y, x] = median;
                        }
                    }
                }
            }
        }
 public void TestConvertRgb24Image()
 {
     String imgPath0 = "..\\images\\yilagou_1280_720_24.jpg";
     Bitmap map = new Bitmap(imgPath0);
     Color c = map.GetPixel(0, 0);
     Console.WriteLine(c.ToString());
     ImageRgb24 r = new ImageRgb24(map);
     Rgb24 cr = r[0, 0];
     Console.WriteLine(cr.ToString());
     Bitmap to = r.ToBitmap();
     Color tc = to.GetPixel(0, 0);
     Console.WriteLine(tc.ToString());
     Assert.AreEqual(c.R, cr.Red);
     Assert.AreEqual(c.G, cr.Green);
     Assert.AreEqual(c.B, cr.Blue);
     Assert.AreEqual(c.R, tc.R);
     Assert.AreEqual(c.G, tc.G);
     Assert.AreEqual(c.B, tc.B);
 }