예제 #1
0
        private void valueChangeGaussianEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            double sum   = 0;
            int    count = Row;
            int    start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    if (IsRange(bitmapResult.GetPixel(i, j)))
                    {
                        double sumR = 0, sumG = 0, sumB = 0;
                        sum = 0;
                        for (int w = 0; w < count; w++)
                        {
                            for (int h = 0; h < count; h++)
                            {
                                double c = 0, p = Math.Pow(w - start, 2), q = Math.Pow(h - start, 2), w1;
                                w1    = Math.Pow(Math.E, -(p + q) / (2 * sigma_d * sigma_d));
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0);
                                sumR += c * w1;
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1);
                                sumG += c * w1;
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2);
                                sumB += c * w1;
                                sum  += w1;
                            }
                        }
                        bitmapResult.SetPixel(i, j, Color.FromArgb((int)(sumR / sum), (int)(sumG / sum), (int)(sumB / sum)));
                    }
                }
            }
        }
예제 #2
0
        private void valueChangeEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            x            = bitmapResult.Width;
            y            = bitmapResult.Height;
            Complex32[] matrix = new Complex32[x * y];
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    matrix[i * x + j] = bitmapResult.GetPixel(i, j).R;
                }
            }
            var ms = matrix.Clone();

            Fourier.Forward2D(matrix, x, y);

            //for (int i = 0; i < x; i++)
            //{
            //    for (int j = 0; j < y; j++)
            //    {
            //        var gray =  (byte)matrix[i * x + j].r
            //        bitmapResult.SetPixel(i, j, Color.FromArgb(matrix[i * x + j], matrix[i * x + j], matrix[i * x + j]));
            //    }
            //}
        }
예제 #3
0
        private void valueChangeMeanEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            int sum = 0;

            foreach (var item in Model)
            {
                sum += item;
            }
            int count = Row;
            int start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    if (IsRange(bitmapResult.GetPixel(i, j)))
                    {
                        int sumR = 0, sumG = 0, sumB = 0;
                        for (int w = 0; w < count; w++)
                        {
                            for (int h = 0; h < count; h++)
                            {
                                sumR += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0) * Model[w, h];
                                sumG += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1) * Model[w, h];
                                sumB += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2) * Model[w, h];
                            }
                        }
                        bitmapResult.SetPixel(i, j, Color.FromArgb(sumR / sum, sumG / sum, sumB / sum));
                    }
                }
            }
        }
예제 #4
0
        private void valueChangeUnsharp_MaskingEvent()
        {
            //Model = new List<int[]> { new int[3] { 1, 1, 1 }, new int[3] { 1, 1, 1 }, new int[3] { 1, 1, 1 } };
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            int sum = 0;

            foreach (var item in Model)
            {
                foreach (var it in item)
                {
                    sum += it;
                }
            }
            int count = Model.Count;
            int start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    int sumR = 0, sumG = 0, sumB = 0;
                    for (int w = 0; w < count; w++)
                    {
                        for (int h = 0; h < count; h++)
                        {
                            sumR += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0) * Model[w][h];
                            sumG += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1) * Model[w][h];
                            sumB += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2) * Model[w][h];
                        }
                    }
                    bitmapResult.SetPixel(i, j, Color.FromArgb(sumR / sum, sumG / sum, sumB / sum));
                }
            }
            // 2 * BitmapOrigin - bitmapResult
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    int[] colorO = new int[3] {
                        BitmapOrigin.GetPixel(i, j).R, BitmapOrigin.GetPixel(i, j).G, BitmapOrigin.GetPixel(i, j).B
                    };
                    int[] colorR = new int[3] {
                        bitmapResult.GetPixel(i, j).R, bitmapResult.GetPixel(i, j).G, bitmapResult.GetPixel(i, j).B
                    };
                    int[] color = new int[3];
                    for (int c = 0; c < 3; c++)
                    {
                        color[c] = Range(2 * colorO[c] - colorR[c]);
                    }
                    bitmapResult.SetPixel(i, j, Color.FromArgb(color[0], color[1], color[2]));
                }
            }
        }
예제 #5
0
        private void valueChangeEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            double sum = _R + _G + _B;
            double r   = _R / sum;
            double g   = _G / sum;
            double b   = _B / sum;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    var color = bitmapResult.GetPixel(i, j);
                    int gray  = (int)(color.R * r + color.G * g + color.B * b);
                    bitmapResult.SetPixel(i, j, Color.FromArgb(gray));
                }
            }
        }
예제 #6
0
        private void valueChangeLaplaceEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;

            int[,,] color = new int[3, x, y];

            int count = Model.Count;
            int start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    int[] sumColor = new int[3] {
                        0, 0, 0
                    };
                    for (int w = 0; w < count; w++)
                    {
                        for (int h = 0; h < count; h++)
                        {
                            for (int c = 0; c < 3; c++)
                            {
                                sumColor[c] += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), c) * Model[w][h];
                            }
                        }
                    }
                    color[0, i, j] = sumColor[0];
                    color[1, i, j] = sumColor[1];
                    color[2, i, j] = sumColor[2];
                }
            }
            // 标定
            color = BDFunc(color);
            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    bitmapResult.SetPixel(i, j, Color.FromArgb(color[0, i, j], color[1, i, j], color[2, i, j]));
                }
            }
        }
예제 #7
0
 private void valueChangeEvent()
 {
     try
     {
         bitmapResult = BitmapOrigin.Clone() as Bitmap;
         int x = BitmapOrigin.Width / width;
         int y = BitmapOrigin.Height / height;
         int w = 0, h = 0;
         for (w = 0; w < x; w++)
         {
             for (h = 0; h < y; h++)
             {
                 HE(w * width, h * height, (w + 1) * width, (h + 1) * height);
             }
         }
         HE((w + 1) * width, (h + 1) * height, bitmapResult.Width, BitmapOrigin.Height);
     }
     catch
     {
         MessageBox.Show("图片格式不支持");
     }
 }
예제 #8
0
        public void valueChangeBilateralEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            double sum   = 0;
            int    count = Row;
            int    start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    if (IsRange(bitmapResult.GetPixel(i, j)))
                    {
                        double sumR = 0, sumG = 0, sumB = 0;
                        double r = Gray(bitmapResult.GetPixel(i, j), 0) / 255.0;
                        double g = Gray(bitmapResult.GetPixel(i, j), 1) / 255.0;
                        double b = Gray(bitmapResult.GetPixel(i, j), 2) / 255.0;
                        for (int w = 0; w < count; w++)
                        {
                            for (int h = 0; h < count; h++)
                            {
                                double c, p = Math.Pow(w - start, 2), q = Math.Pow(h - start, 2), w1;
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0) / 255.0;
                                w1    = Math.Pow(Math.E, -(p + q) / (2 * sigma_d * sigma_d)) * Math.Pow(Math.E, -(Math.Pow(r - c, 2)) / (2 * sigma_r * sigma_r));
                                sumR += c * w1;
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1) / 255.0;
                                sumG += c * w1;
                                c     = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2) / 255.0;
                                sumB += c * w1;
                                sum  += w1;
                            }
                        }
                        bitmapResult.SetPixel(i, j, Color.FromArgb((int)(sumR * 255 / sum), (int)(sumG * 255 / sum), (int)(sumB * 255 / sum)));
                        sum = 0;
                    }
                }
            }
        }
예제 #9
0
        private void valueChangeEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            int x = BitmapOrigin.Width;
            int y = BitmapOrigin.Height;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    var color = bitmapResult.GetPixel(i, j);
                    if (IsRange(color))
                    {
                        double r  = (double)(color.R) / 255;
                        double g  = (double)(color.G) / 255;
                        double b  = (double)(color.B) / 255;
                        int    sR = (int)(c * Math.Pow(r, gamma) * 255);
                        int    sG = (int)(c * Math.Pow(g, gamma) * 255);
                        int    sB = (int)(c * Math.Pow(b, gamma) * 255);
                        bitmapResult.SetPixel(i, j, Color.FromArgb(sR, sG, sB));
                    }
                }
            }
        }
예제 #10
0
        private void valueChangeGradientEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;

            int[,,] color = new int[3, x, y];
            int[] max = new int[3] {
                0, 0, 0
            };
            int[] min = new int[3] {
                256, 256, 256
            };
            int[,,] M = new int[2, 3, 3]
            {
                {
                    { -1, -2, -1 },
                    { 0, 0, 0 },
                    { 1, 2, 1 }
                },
                {
                    { -1, 0, 1 },
                    { -2, 0, 2 },
                    { -1, 0, 1 }
                }
            };
            int start = 1;
            int count = 3;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    int[,] sumColor = new int[2, 3] {
                        { 0, 0, 0 }, { 0, 0, 0 }
                    };
                    for (int s = 0; s < 2; s++)
                    {
                        for (int w = 0; w < count; w++)
                        {
                            for (int h = 0; h < count; h++)
                            {
                                for (int c = 0; c < 3; c++)
                                {
                                    sumColor[s, c] += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), c) * M[s, w, h];
                                }
                            }
                        }
                        sumColor[s, 0] = Math.Abs(sumColor[s, 0]);
                        sumColor[s, 1] = Math.Abs(sumColor[s, 1]);
                        sumColor[s, 2] = Math.Abs(sumColor[s, 2]);
                    }
                    color[0, i, j] = (sumColor[0, 0] + sumColor[1, 0]);
                    color[1, i, j] = (sumColor[0, 1] + sumColor[1, 1]);
                    color[2, i, j] = (sumColor[0, 2] + sumColor[1, 2]);
                }
            }
            color = BDFunc(color);
            //叠加原图
            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    bitmapResult.SetPixel(i, j, Color.FromArgb(color[0, i, j], color[1, i, j], color[2, i, j]));
                }
            }
        }
예제 #11
0
        private void valueChangeMiddleEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            int count = Model.Length;
            int start = count / 2;

            for (int i = start; i < x - start; i++)
            {
                for (int j = start; j < y - start; j++)
                {
                    if (IsRange(bitmapResult.GetPixel(i, j)))
                    {
                        int[,] PixR = new int[count, count];
                        int[,] PixG = new int[count, count];
                        int[,] PixB = new int[count, count];
                        for (int w = 0; w < count; w++)
                        {
                            for (int h = 0; h < count; h++)
                            {
                                PixR[w, h] = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0) * Model[w, h];
                                PixG[w, h] = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1) * Model[w, h];
                                PixB[w, h] = Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2) * Model[w, h];
                            }
                        }
                        int middleR = PixR[0, 0], middleG = PixG[0, 0], middleB = PixB[0, 0];
                        int x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0;
                        for (int m = 0; m < (count * count) / 2 + 1; m++)
                        {
                            middleR = 255;
                            middleG = 255;
                            middleB = 255;
                            for (int n = 0; n < count; n++)
                            {
                                for (int l = 0; l < count; l++)
                                {
                                    if (middleR > PixR[n, l])
                                    {
                                        middleR = PixR[n, l];
                                        x1      = n;
                                        x2      = l;
                                    }
                                    if (middleG > PixG[n, l])
                                    {
                                        middleG = PixG[n, l];
                                        x3      = n;
                                        x4      = l;
                                    }
                                    if (middleB > PixB[n, l])
                                    {
                                        middleB = PixB[n, l];
                                        x5      = n;
                                        x6      = l;
                                    }
                                }
                            }
                            PixR[x1, x2] = 255;
                            PixG[x3, x4] = 255;
                            PixB[x5, x6] = 255;
                        }
                        bitmapResult.SetPixel(i, j, Color.FromArgb(middleR, middleG, middleB));
                    }
                }
            }
        }