static void TestLevels() { var bmp1 = (Bitmap)Bitmap.FromFile("meta1.png"); var bmp2 = (Bitmap)Bitmap.FromFile("meta2.png"); LevelsLinear filter = new LevelsLinear(); // set ranges filter.Input = new IntRange(150, 255); // apply the filter var sw = Stopwatch.StartNew(); filter.ApplyInPlace(bmp2); sw.Stop(); var contrast = new ContrastStretch(); var bmp4 = contrast.Apply(bmp2); var bmp3 = ImageUtil.AdjustImage(bmp2, contrast: 2f); }
public double GetTemperature() { var temp = 0.0; var image = Image.FromFile(filename); var grayscale = new Grayscale(0.2125, 0.7154, 0.0721); image = grayscale.Apply(image); var invert = new Invert(); image = invert.Apply(image); var stats = new ImageStatistics(image); var levelsLinear = new LevelsLinear { InGray = stats.Gray.GetRange(2.90) }; image = levelsLinear.Apply(image); var contrast = new ContrastStretch(); image = contrast.Apply(image); var erosion = new Erosion(); image = erosion.Apply(image); var blur = new GaussianBlur(2, 3); image = blur.Apply(image); var threshold = new Threshold(79); image = threshold.Apply(image); image.Save(processedFileName, System.Drawing.Imaging.ImageFormat.Jpeg); image.Dispose(); var text = Recognise(); double.TryParse(text.Replace(',', '.'), out temp); return temp; }
public static Bitmap AutoColorCorrections(Bitmap source) { if (source == null) throw new ArgumentNullException("source"); //Bitmap output = null; ContrastStretch filter = new ContrastStretch(); filter.ApplyInPlace(source); //float brightness = 1.0f; // no change in brightness //float contrast = 2.0f; // twice the contrast //float gamma = 1.0f; // no change in gamma //float adjustedBrightness = brightness - 1.0f; //// create matrix that will brighten and contrast the image //float[][] ptsArray ={ // new float[] {contrast, 0, 0, 0, 0}, // scale red // new float[] {0, contrast, 0, 0, 0}, // scale green // new float[] {0, 0, contrast, 0, 0}, // scale blue // new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha // new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}}; //using (ImageAttributes imageAttrs = new ImageAttributes()) //{ // imageAttrs.ClearColorMatrix(); // imageAttrs.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap); // imageAttrs.SetGamma(gamma, ColorAdjustType.Bitmap); // using (Graphics g = Graphics.FromImage(output)) // { // g.DrawImage(source, new Rectangle(0, 0, output.Width, output.Height), 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, imageAttrs); // } //} return source; }
private void Contrast_scretchFunc(ref Bitmap frame, int par_int, double par_d, int par_R, int par_G, int par_B) { ContrastStretch filter = new ContrastStretch(); // process image filter.ApplyInPlace(frame); }
public static Bitmap ApplyContrastStretch(Bitmap pBitmap) { var filter = new ContrastStretch(); return filter.Apply(pBitmap); }
public BitmapSource Apply(BitmapSource image) { var filter = new ContrastStretch(); var bmp = filter.Apply(image.ToBitmap()); return bmp.ToBitmapImage(); }
private void contrastStretch_Click(object sender, RoutedEventArgs e) { if (contrastStretch.IsChecked == true) { ContrastStretch filter = new ContrastStretch(); filter.ApplyInPlace(mainPhoto); Photography.Source = ToBitmapImage(mainPhoto); } else { UpdatePicture(ImageURL); Photography.Source = ToBitmapImage(mainPhoto); } mainPhotoIS = Photography.Source; UpdateHistograms(null); UpdateChannelPreviews(null); }
private void Contrast_scretchFunc(ref Bitmap frame) { ContrastStretch filter = new ContrastStretch(); // process image filter.ApplyInPlace(frame); }