示例#1
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;
                }
            }
        }
示例#2
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;
        }