private static Bitmap ContrastRGBProcess(Bitmap img, double Rc_low_in, double Rc_high_in, double Gc_low_in, double Gc_high_in, double Bc_low_in, double Bc_high_in, double Rc_low_out, double Rc_high_out, double Gc_low_out, double Gc_high_out, double Bc_low_out, double Bc_high_out, double gamma) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); if (Checks.RGBinput(img)) { List <ArraysListInt> ColorList = Helpers.GetPixels(img); string outName = String.Empty; //default //gamma - linear mapping gamma = 1 //In values between low_in and high_in //Only positive values in range [0:1] //low and high specifying the In contrast limits double[] RcIn = new double[2] { 0, 1 }; double[] GcIn = new double[2] { 0, 1 }; double[] BcIn = new double[2] { 0, 1 }; //make Out intensity to values between low_out and high_out //Only positive values in range [0:1; 0:1] // If high_out < low_out, the output image is reversed, as in a photographic negative. double[] RcOut = new double[2] { 0, 1 }; double[] GcOut = new double[2] { 0, 1 }; double[] BcOut = new double[2] { 0, 1 }; if (Rc_low_in > 1 || Rc_high_in > 1 || Gc_low_in > 1 || Gc_high_in > 1 || Bc_low_in > 1 || Bc_high_in > 1 || Rc_low_in < 0 || Rc_high_in < 0 || Gc_low_in < 0 || Gc_high_in < 0 || Bc_low_in < 0 || Bc_high_in < 0 || Rc_low_out > 1 || Rc_high_out > 1 || Gc_low_out > 1 || Gc_high_out > 1 || Bc_low_out > 1 || Bc_high_out > 1 || Rc_low_out < 0 || Rc_high_out < 0 || Gc_low_out < 0 || Gc_high_out < 0 || Bc_low_out < 0 || Bc_high_out < 0) { Console.WriteLine("low_in limit and high_in limits must be in range [0:1]\n" + "low_out and high_out limits must be in range [0:1] or [1 0]"); } else if (Rc_low_in >= Rc_high_in || Gc_low_in >= Gc_high_in || Bc_low_in >= Bc_high_in) { Console.WriteLine("low_in limit must be less then high_in limit for each color plane"); } else { RcIn = new double[2] { Rc_low_in, Rc_high_in }; GcIn = new double[2] { Gc_low_in, Gc_high_in }; BcIn = new double[2] { Bc_low_in, Bc_high_in }; if (Rc_low_out != 0 || Rc_high_out != 0 || Gc_low_out != 0 || Gc_high_out != 0 || Bc_low_out != 0 || Bc_high_out != 0) { RcOut = new double[2] { Rc_low_out, Rc_high_out }; GcOut = new double[2] { Gc_low_out, Gc_high_out }; BcOut = new double[2] { Bc_low_out, Bc_high_out }; } //prevent obtain black square if all low_out = high_out = 0 in this case used default Out { 0, 1 }; //Convert integer values using lookup table var ContRc = ContrastProcess.InlutContrast(ColorList[0].Color, ContrastProcess.CountLut(RcIn, RcOut, gamma)); var ContGc = ContrastProcess.InlutContrast(ColorList[1].Color, ContrastProcess.CountLut(GcIn, GcOut, gamma)); var ContBc = ContrastProcess.InlutContrast(ColorList[2].Color, ContrastProcess.CountLut(BcIn, BcOut, gamma)); image = Helpers.SetPixels(image, ContRc, ContGc, ContBc); } } return(image); }
private static Bitmap ContrastBlackWhiteProcess(Bitmap img, double low_in, double high_in, double low_out, double high_out, double gamma) { int[,] GrayC = new int[img.Height, img.Width]; Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); if (Depth == 8 || Checks.BlackandWhite24bppCheck(img)) { GrayC = MoreHelpers.BlackandWhiteProcessHelper(img); //default //gamma - linear mapping gamma = 1 //Make In intensity to values between low_in and high_in //Only positive values in range [0:1] double[] In = new double[2] { 0, 1 }; //make Out intensity to values between low_out and high_out //Only positive values in range [0:1; 0:1] //If high_out < low_out, the output image is reversed, as in a photographic negative. double[] Out = new double[2] { 0, 1 }; int[,] Cont = new int[img.Height, img.Width]; if (low_in > 1 || high_in > 1 || low_in < 0 || high_in < 0 || low_out > 1 || high_out > 1 || low_out < 0 || high_out < 0) { Console.WriteLine("low_in and high_in limits must be in range [0:1] \n" + "low_out and high_out limits must be in range [1:0] or [0 1]"); } else if (low_in >= high_in) { Console.WriteLine("low_in must be less then high_in"); } else { In = new double[2] { low_in, high_in }; //low and high specifying the contrast limits //Find In limits to contrast image Based on it`s intensity //No sence for values 0.5 and more. 0.01 - here use only default value if (low_in == 0.98 && high_in == 0.99 && low_out == 0.99 && high_out == 0.99) //so bad { In = ContrastProcess.Stretchlims(GrayC, 0.01); //number - intensity in % pixels saturated at low and high intensities of image } else if (low_out != 0 || high_out != 0) { Out = new double[2] { low_out, high_out } } ; //prevent obtain black square if low_out = high_out = 0 in this case used default Out { 0, 1 }; Cont = ContrastProcess.InlutContrast(GrayC, ContrastProcess.CountLut(In, Out, gamma)); //Convert integer values using lookup table image = Helpers.SetPixels(image, Cont, Cont, Cont); if (Depth != 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } } } else { Console.WriteLine("There non 8bit or 24bit black and white image at input. Method: ContrastBlackandWhite()"); } return(image); }