示例#1
0
        public Color[,] LinearFilter(Color[,] input, double[,] Mask, int originX, int originY, string Postprocessing)
        {
            int width = input.GetLength(0);
            int height = input.GetLength(1);
            int mask_width = Mask.GetLength(0);
            int mask_height = Mask.GetLength(1);

            Color[,] temp = Padding(input, Mask, originX, originY);
            Color[,] result = new Color[width, height];
            Data[,] data = new Data[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Data sum;
                    sum.R_Val = sum.G_Val = sum.B_Val = 0;
                    for (int k = 0; k < mask_height; k++)
                    {
                        for (int m = 0; m < mask_width; m++)
                        {
                            sum.R_Val += Mask[m, k] * temp[i + m, j + k].R;
                            sum.G_Val += Mask[m, k] * temp[i + m, j + k].G;
                            sum.B_Val += Mask[m, k] * temp[i + m, j + k].B;
                        }
                    }
                    if (Postprocessing == "Cutoff")
                    {
                        sum.R_Val = pixel.cutOff(sum.R_Val);
                        sum.G_Val = pixel.cutOff(sum.G_Val);
                        sum.B_Val = pixel.cutOff(sum.B_Val);
                        result[i, j] = Color.FromArgb((int)sum.R_Val, (int)sum.G_Val, (int)sum.B_Val);

                    }
                    else if (Postprocessing == "Absolute")
                    {

                        sum.R_Val = Math.Abs(sum.R_Val);
                        sum.G_Val = Math.Abs(sum.G_Val);
                        sum.B_Val = Math.Abs(sum.B_Val);
                        data[i, j] = sum;
                    }
                    else if (Postprocessing == "None")
                    {
                        result[i, j] = Color.FromArgb((int)sum.R_Val, (int)sum.G_Val, (int)sum.B_Val);
                    }
                }
            }
            if (Postprocessing == "Absolute")
            {
                result = pixel.Contrast(0, 255, data);
            }
            return result;
        }
示例#2
0
        private void Min_Max_Value(Data[,] Org_Buffer, out Data Min, out Data Max)
        {
            int width = Org_Buffer.GetLength(0);
            int height = Org_Buffer.GetLength(1);
            Min.B_Val = Min.R_Val = Min.G_Val = 255;
            Max.B_Val = Max.R_Val = Max.G_Val = 0;

            for (int j = 0; j < height; ++j)
            {
                for (int i = 0; i < width; ++i)
                {
                    if (Org_Buffer[i, j].R_Val < Min.R_Val)
                        Min.R_Val = Org_Buffer[i, j].R_Val;
                    if (Org_Buffer[i, j].G_Val < Min.G_Val)
                        Min.G_Val = Org_Buffer[i, j].G_Val;
                    if (Org_Buffer[i, j].B_Val < Min.B_Val)
                        Min.B_Val = Org_Buffer[i, j].B_Val;
                    //   //   //   //   //   //
                    if (Org_Buffer[i, j].R_Val > Max.R_Val)
                        Max.R_Val = Org_Buffer[i, j].R_Val;
                    if (Org_Buffer[i, j].G_Val > Max.G_Val)
                        Max.G_Val = Org_Buffer[i, j].G_Val;
                    if (Org_Buffer[i, j].B_Val > Max.B_Val)
                        Max.B_Val = Org_Buffer[i, j].B_Val;
                }
            }
        }
示例#3
0
 private Data[] Hist_Normalize(Data[] Hist_Data)
 {
     Data maxRGB = get_max_value(Hist_Data);
     Data[] Norm_Hist_Data = new Data[256];
     for (int i = 0; i < 256; ++i)
     {
         Norm_Hist_Data[i].R_Val = ((Hist_Data[i].R_Val / maxRGB.R_Val) * 256);
         Norm_Hist_Data[i].G_Val = ((Hist_Data[i].G_Val / maxRGB.G_Val) * 256);
         Norm_Hist_Data[i].B_Val = ((Hist_Data[i].B_Val / maxRGB.B_Val) * 256);
     }
     return Norm_Hist_Data;
 }
示例#4
0
 private Data[] Histogram_data(int width, int height, Color[,] Org_Buffer)
 {
     Data[] Hist_Data = new Data[256];
     for (int j = 0; j < height; ++j)
     {
         for (int i = 0; i < width; ++i)
         {
             ++Hist_Data[Org_Buffer[i, j].R].R_Val;
             ++Hist_Data[Org_Buffer[i, j].G].B_Val;
             ++Hist_Data[Org_Buffer[i, j].B].G_Val;
         }
     }
     Data[] Norm_Hist_Data = Hist_Normalize(Hist_Data);
     return Norm_Hist_Data;
 }
示例#5
0
 private Data get_max_value(Data[] Hist_Data)
 {
     Data maxRGB = new Data();
     for (int i = 0; i < 256; ++i)
     {
         if (Hist_Data[i].R_Val > maxRGB.R_Val)
             maxRGB.R_Val = Hist_Data[i].R_Val;
         if (Hist_Data[i].G_Val > maxRGB.G_Val)
             maxRGB.G_Val = Hist_Data[i].G_Val;
         if (Hist_Data[i].B_Val > maxRGB.B_Val)
             maxRGB.B_Val = Hist_Data[i].B_Val;
     }
     return maxRGB;
 }
示例#6
0
 public Color[,] Gamma(Color[,] Org_Buffer, double Gamma_value)
 {
     int width = Org_Buffer.GetLength(0);
     int height = Org_Buffer.GetLength(1);
     Color[,] Org_Buffer_temp = new Color[width, height];
     Data[,] RGB = new Data[width, height];
     for (int j = 0; j < height; ++j)
     {
         for (int i = 0; i < width; ++i)
         {
             RGB[i, j].R_Val = Math.Pow(Org_Buffer[i, j].R, Gamma_value);
             RGB[i, j].G_Val = Math.Pow(Org_Buffer[i, j].G, Gamma_value);
             RGB[i, j].B_Val = Math.Pow(Org_Buffer[i, j].B, Gamma_value);
         }
     }
     Org_Buffer_temp = Contrast(0, 255, RGB);
     return Org_Buffer_temp;
 }
示例#7
0
        //Normalization int Data type [overloaded Function]
        public Color[,] Contrast(int NewMin, int NewMax, Data[,] Org_Buffer)
        {
            //NewVal = [(OldVal – OldMin)/(OldMax – OldMin)] × (NewMax – NewMin) + NewMin
            Data OldMin, OldMax;
            Min_Max_Value(Org_Buffer, out OldMin, out OldMax);
            int width = Org_Buffer.GetLength(0);
            int height = Org_Buffer.GetLength(1);
            Color[,] Org_Buffer_temp = new Color[width, height];
            Data data;
            //IMPORTANT ==> we Suppose that NewMax & NewMin is one for R & G & B .. the user Enter one value fo 3 colors
            for (int j = 0; j < height; ++j)
            {
                for (int i = 0; i < width; ++i)
                {
                    data.R_Val = (((Org_Buffer[i, j].R_Val - OldMin.R_Val) / (OldMax.R_Val - OldMin.R_Val)) * (NewMax - NewMin) + NewMin);
                    data.R_Val = cutOff(data.R_Val);

                    data.G_Val = (((Org_Buffer[i, j].G_Val - OldMin.G_Val) / (OldMax.G_Val - OldMin.G_Val)) * (NewMax - NewMin) + NewMin);
                    data.G_Val = cutOff(data.G_Val);

                    data.B_Val = (((Org_Buffer[i, j].B_Val - OldMin.B_Val) / (OldMax.B_Val - OldMin.B_Val)) * (NewMax - NewMin) + NewMin);
                    data.B_Val = cutOff(data.B_Val);

                    Org_Buffer_temp[i, j] = Color.FromArgb((int)data.R_Val, (int)data.G_Val, (int)data.B_Val);
                }
            }
            return Org_Buffer_temp;
        }