public static bool ToYCbCr(ref GlobalObjects GObjects) { if (GObjects.MainPicture == null) { return(false); } GObjects.Chanel1 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel2 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel3 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); for (int i = 0; i < GObjects.MainPicture.Height; i++) { for (int j = 0; j < GObjects.MainPicture.Width; j++) { int R = GObjects.MainPicture.GetPixel(j, i).R; int G = GObjects.MainPicture.GetPixel(j, i).G; int B = GObjects.MainPicture.GetPixel(j, i).B; int YColor = Math.Min(255, Math.Max(0, Convert.ToInt32(0.299 * R + 0.587 * G + 0.114 * B))); int CbColor = Math.Min(255, Math.Max(0, Convert.ToInt32(128 - 0.169 * R - 0.331 * G + 0.5 * B))); int CrColor = Math.Min(255, Math.Max(0, Convert.ToInt32(128 + 0.5 * R - 0.419 * G - 0.081 * B))); GObjects.Chanel1.SetPixel(j, i, Color.FromArgb(YColor, YColor, YColor)); GObjects.Chanel2.SetPixel(j, i, Color.FromArgb(127, 255 - CbColor, CbColor)); GObjects.Chanel3.SetPixel(j, i, Color.FromArgb(CrColor, 255 - CrColor, 127)); } } return(true); }
public static bool AddImage(ref GlobalObjects GObjects, int width, int height, int BigWidth, int BigHeight) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image Files(*.BMP; *.JPG; *.PNG; *.GIF)| *.BMP; *.JPG; *.PNG; *.GIF"; openFileDialog.Title = "Open an Image File"; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == DialogResult.OK) { GObjects.MainPicture = new DirectBitmap(width, height); Bitmap temp = new Bitmap(Image.FromFile(openFileDialog.FileName), width, height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { GObjects.MainPicture.SetPixel(j, i, temp.GetPixel(j, i)); } } temp = new Bitmap(Image.FromFile(openFileDialog.FileName), BigWidth, BigHeight); GObjects.MainPictureOnView = new DirectBitmap(BigWidth, BigHeight); for (int i = 0; i < BigHeight; i++) { for (int j = 0; j < BigWidth; j++) { GObjects.MainPictureOnView.SetPixel(j, i, temp.GetPixel(j, i)); } } temp.Dispose(); return(true); } return(false); }
public Form1() { GObjects = new GlobalObjects(); InitializeComponent(); GObjects.finished = true; SeparationOption_Combo.SelectedIndex = 0; Illuminant_Combo.Items.AddRange(GObjects.IlluminnatsNames); ColorSpace_Combo.Items.AddRange(GObjects.ColorSpaceNames); ColorSpace_Combo.SelectedIndex = 0; GObjects.sRGB2XYZs = ImageControl.TransformationMatrix(GObjects.ColorSpaceValues[0], GObjects.IlluminantsValues[5]); GObjects.XYZ2sRGB = MatrixCalculations.MatrixInverse(GObjects.sRGB2XYZs); //spytac o LAB }
public static bool ToHSV(ref GlobalObjects GObjects) { if (GObjects.MainPicture == null) { return(false); } GObjects.Chanel1 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel2 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel3 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); for (int i = 0; i < GObjects.MainPicture.Height; i++) { for (int j = 0; j < GObjects.MainPicture.Width; j++) { double R = GObjects.MainPicture.GetPixel(j, i).R / 255.0; double G = GObjects.MainPicture.GetPixel(j, i).G / 255.0; double B = GObjects.MainPicture.GetPixel(j, i).B / 255.0; double MinRGB = Math.Min(R, Math.Min(G, B)); double MaxRGB = Math.Max(R, Math.Max(G, B)); double H = CalculateH(R, G, B, MaxRGB, MinRGB); double S = 0; if (MaxRGB != 0) { S = (MaxRGB - MinRGB) / MaxRGB; } double V = MaxRGB; int iH = Convert.ToInt32(255 * H / 360); int iS = Convert.ToInt32(255 * S); int iV = Convert.ToInt32(255 * V); GObjects.Chanel1.SetPixel(j, i, Color.FromArgb(iH, iH, iH)); GObjects.Chanel2.SetPixel(j, i, Color.FromArgb(iS, iS, iS)); GObjects.Chanel3.SetPixel(j, i, Color.FromArgb(iV, iV, iV)); } } return(true); }
public static bool ToLAB(ref GlobalObjects GObjects, ColorSpace colorSpace, doublePoint whitePoint) { if (GObjects.MainPicture == null) { return(false); } GObjects.Chanel1 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel2 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); GObjects.Chanel3 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height); double[][] matrix = TransformationMatrix(colorSpace, whitePoint); double[][] WPvector = new double[][] { new double[] { whitePoint.X / whitePoint.Y }, new double[] { 1 }, new double[] { (1 - whitePoint.X - whitePoint.Y) / whitePoint.Y } }; for (int i = 0; i < GObjects.MainPicture.Height; i++) { for (int j = 0; j < GObjects.MainPicture.Width; j++) { double R = Math.Pow(GObjects.MainPicture.GetPixel(j, i).R / 255.0, colorSpace.Gamma); double G = Math.Pow(GObjects.MainPicture.GetPixel(j, i).G / 255.0, colorSpace.Gamma); double B = Math.Pow(GObjects.MainPicture.GetPixel(j, i).B / 255.0, colorSpace.Gamma); double[][] RGBvector = new double[][] { new double[] { R }, new double[] { G }, new double[] { B } }; double[][] XYZvector = MatrixCalculations.MatrixProduct(matrix, RGBvector); var Values = VectorFunction(XYZvector[0][0] / WPvector[0][0], XYZvector[1][0] / WPvector[1][0], XYZvector[2][0] / WPvector[2][0]); int Lvalue = Convert.ToInt32(116 * Values.fy - 16); int Avalue = Convert.ToInt32(500 * (Values.fx - Values.fy)); int Bvalue = Convert.ToInt32(200 * (Values.fy - Values.fz)); GObjects.Chanel1.SetPixel(j, i, Color.FromArgb(Math.Max(Math.Min(255, Lvalue), 0), Math.Max(Math.Min(255, Lvalue), 0), Math.Max(Math.Min(255, Lvalue), 0))); GObjects.Chanel2.SetPixel(j, i, Color.FromArgb(Math.Max(0, Math.Min(255, 127 + Avalue)), Math.Max(0, Math.Min(255, 127 - Avalue)), 127)); GObjects.Chanel3.SetPixel(j, i, Color.FromArgb(Math.Max(0, Math.Min(255, 127 + Bvalue)), 127, Math.Max(0, Math.Min(255, 127 - Bvalue)))); } } return(true); }
public static void CreateBase(ref GlobalObjects GObjects, int width, int height, int BigWidth, int BigHeight) { GObjects.MainPicture = Createtemp(width, height); GObjects.MainPictureOnView = Createtemp(BigWidth, BigHeight); }