public override void ThreadMethod(object poThreadParameter) { // This is the code that is going to be run by the thread // It has access to all the instance variable of this class // It receives the instance as a parameter // We must typecast poThreadParameter to BrightnessAdjustmentPiece (inherited from ParallelAlgorithmPiece) // to gain access to its members BrightnessAdjustmentPiece loPiece; loPiece = (BrightnessAdjustmentPiece)poThreadParameter; // Retrieve the thread number received in object poThreadParameter, in piThreadNumber property long liPieceNumber = loPiece.piThreadNumber; //Format the image according to AForge.NET needs to apply the filter AForge.Imaging.Image.FormatImage(ref proBitmap); // Create an instance of the brightness correction filter AForge.Imaging.Filters.BrightnessCorrection loBrightnessCorrection = new AForge.Imaging.Filters.BrightnessCorrection(priBrightnessDelta); // Process the image (correct the brightness) loBrightnessCorrection.ApplyInPlace(proBitmap); // Code added in the WaitHandle.WaitAll version // The thread finished its work. Signal that the work item has finished. poAutoResetEvent.Set(); }
// 밝게 public static Bitmap bright(Bitmap source) { ///////////// ini 객체 생성 시작 ///////////////////////////////////////////////////// //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe"); string pathini = exefileinfo.Directory.FullName.ToString(); //프로그램 실행되고 있는데 path 가져오기 string fileName = @"\PLOCRconfig.ini"; // 환경설정 파일명 string filePath = pathini + fileName; //ini 파일 경로 PLOCR.IniUtil ini = new PLOCR.IniUtil(filePath); // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌) //////////// ini 객체 생성 끝 ///////////////////////////////////////////////////////// int order = int.Parse(ini.GetIniValue("밝기값", "밝게횟수")); for (int i = 0; i < order; i++) { // create filter BrightnessCorrection filter = new BrightnessCorrection(+10); // apply the filter filter.ApplyInPlace(source); } return source; }
private static Bitmap changeHSL(Bitmap bmp, int h, double s, double l, bool keepBW, bool keepGray, int grayTolerance) { s = Math.Round(s / 100, 2); l = Math.Round(l / 100, 2); HueModifierRelative hue = new HueModifierRelative(h, keepBW); SaturationCorrection saturation = new SaturationCorrection(s, keepBW, keepGray, grayTolerance); BrightnessCorrection bright = new BrightnessCorrection(l, keepBW, keepGray, grayTolerance); hue.ApplyInPlace(bmp); saturation.ApplyInPlace(bmp); bright.ApplyInPlace(bmp); return bmp; }
/// <summary> /// /// </summary> /// <param name="img"></param> /// <returns></returns> public GameLogic ScrapeBoardFromImage(Bitmap img) { // filter board's color to better identify tiles Blur blur = new Blur(); blur.Threshold = 1; blur.ApplyInPlace(img); BrightnessCorrection brightness_filter = new BrightnessCorrection(-30); brightness_filter.ApplyInPlace(img); HSLFiltering luminance_filter = new HSLFiltering(); luminance_filter.Luminance = new Range(0.50f, 1); luminance_filter.ApplyInPlace(img); img.Save("c:\\users\\breiche\\pictures\\filtered.bmp", ImageFormat.Bmp); DetectBlobsInImage(img); img.Save("c:\\users\\breiche\\pictures\\blobs.bmp", ImageFormat.Bmp); return new GameLogic(0, 0); }
// 밝기값 밝게 하기, 횟수 기록 private void button32_Click(object sender, EventArgs e) { ///////////// ini 객체 생성 시작 ///////////////////////////////////////////////////// //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe"); string pathini = exefileinfo.Directory.FullName.ToString(); //프로그램 실행되고 있는데 path 가져오기 string fileName = @"\PLOCRconfig.ini"; // 환경설정 파일명 string filePath = pathini + fileName; //ini 파일 경로 DocumentAnalysis.IniUtil ini = new DocumentAnalysis.IniUtil(filePath); // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌) //////////// ini 객체 생성 끝 ///////////////////////////////////////////////////////// //Bitmap source = (Bitmap)pictureBox1.Image; Bitmap source = Global.source; // create filter BrightnessCorrection filter = new BrightnessCorrection(+10); // apply the filter filter.ApplyInPlace(source); Global.source = source; pictureBox1.Image = Global.source; pictureBox1.Invalidate(); textBox22.Text = (int.Parse(textBox22.Text) + 1).ToString(); ini.SetIniValue("밝기값", "밝게횟수", textBox22.Text.ToString()); //string path = calculator.CreateFileCheck("C:\\Program Files\\PLOCR\\prescription.png"); //pictureBox1.Image.Save(path); }
/// <summary> /// Modifica el brillo y contraste de la imagen que aparece en pantalla /// </summary> private void Filtrar() { Bitmap temp = new Bitmap(padre.actual.datacuboHigh.dataCube[trackElementos.Value - 1].bmp); AForge.Imaging.Filters.BrightnessCorrection brillo = new AForge.Imaging.Filters.BrightnessCorrection(Convert.ToInt32(trackBrillo.Value)); AForge.Imaging.Filters.ContrastCorrection contraste = new AForge.Imaging.Filters.ContrastCorrection(Convert.ToInt32(trackContraste.Value)); contraste.ApplyInPlace(temp); brillo.ApplyInPlace(temp); pictElemento.Image = temp; //pictElemento.Invalidate(); }
public static bool ColorCorrections(string fileName, int brightness, int contrast, double gamma, int hue, float saturation) { if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName"); bool result = false; using (var ms = new MemoryStream(File.ReadAllBytes(fileName))) { using (Bitmap bmp = new Bitmap(ms)) { //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10 if (brightness >= -255 && brightness != 0 && brightness <= 255) { BrightnessCorrection filter = new BrightnessCorrection(brightness); filter.ApplyInPlace(bmp); result = true; } //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10 if (contrast >= -127 && contrast != 0 && contrast <= 127) { ContrastCorrection filter = new ContrastCorrection(contrast); filter.ApplyInPlace(bmp); result = true; } //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0 if (gamma >= 0.1D && gamma != 1D && gamma <= 5D) { GammaCorrection filter = new GammaCorrection(gamma); filter.ApplyInPlace(bmp); result = true; } //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0 if (hue >= -180 && hue != 0 && hue <= 180) { HueModifier filter = new HueModifier(hue); filter.ApplyInPlace(bmp); result = true; } //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1 if (saturation >= -100f && saturation != 0f && saturation <= 100f) { SaturationCorrection filter = new SaturationCorrection(saturation / 100); filter.ApplyInPlace(bmp); result = true; } bmp.Save(fileName); } } return result; }
public static BitmapSource ColorCorrections(BitmapSource source, int brightness, int contrast, double gamma, int hue, float saturation) { if (source == null) throw new ArgumentNullException("source"); BitmapSource output = null; if (source.Format == PixelFormats.Bgr32 && gamma != 1D) { source = new FormatConvertedBitmap(source, PixelFormats.Bgr24, null, 0); } using (Bitmap bmp = Convert(source)) { int bpp = source.Format.BitsPerPixel; if (bpp == 8 || bpp == 24 || bpp == 32) { //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10 if (brightness >= -255 && brightness != 0 && brightness <= 255) { BrightnessCorrection filter = new BrightnessCorrection(brightness); filter.ApplyInPlace(bmp); } //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10 if (contrast >= -127 && contrast != 0 && contrast <= 127) { ContrastCorrection filter = new ContrastCorrection(contrast); filter.ApplyInPlace(bmp); } } if (bpp == 8 || bpp == 24) { //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0 if (gamma >= 0.1D && gamma != 1D && gamma <= 5D) { GammaCorrection filter = new GammaCorrection(gamma); filter.ApplyInPlace(bmp); } } if (bpp == 8 || bpp == 24 || bpp == 32) { //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0 if (hue >= -180 && hue != 0 && hue <= 180) { HueModifier filter = new HueModifier(hue); filter.ApplyInPlace(bmp); } } if (bpp == 24 || bpp == 32) { //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1 if (saturation >= -100f && saturation != 0f && saturation <= 100f) { SaturationCorrection filter = new SaturationCorrection(saturation / 100); filter.ApplyInPlace(bmp); } } output = Convert(bmp); } return CloneImage(output); }
private void ReadAndDisplayDicomFile(string fileName, string fileNameOnly) { dd.DicomFileName = fileName; bool result = dd.dicomFileReadSuccess; if (result == true) { imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; StatusLabel1.Text = fileName + ": " + imageWidth.ToString() + " X " + imageHeight.ToString(); StatusLabel1.Text += " " + bitDepth.ToString() + " bits per pixel"; userControl11.NewImage = true; Text = "DICOM Image Viewer: " + fileNameOnly; if (bitDepth == 16) { pixels16.Clear(); pixels8.Clear(); dd.GetPixels16(ref pixels16); byte[] buffer = new byte[pixels16.Count * 2]; byte[] temp; ByteConverter d = new ByteConverter(); int j = 0; for (int i = 0; i < pixels16.Count; i++) { temp = System.BitConverter.GetBytes(pixels16[i]); buffer[j++] = temp[0]; buffer[j++] = temp[1]; } if (winCentre == 0 && winWidth == 0) { winWidth = 4095; winCentre = 4095 / 2; } string index = ""; foreach (string s in dd.dicomInfo) { if (s.Contains("Image Number")) { index = s; } } userControl11.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true, this); if (processI && int.Parse(index.Split(':')[1]) > 9) { AForge.Imaging.Filters.Grayscale g1 = new Grayscale(0.2125, 0.7154, 0.0721); AForge.Imaging.Filters.BrightnessCorrection bC = new AForge.Imaging.Filters.BrightnessCorrection(brightness); bC.ApplyInPlace(userControl11.bmp); Bitmap image = g1.Apply(userControl11.bmp); thresholding = (int)((dd.windowWidth - dd.windowCentre) * 255 / dd.windowWidth) - trackBar2.Value; label1.Text = thresholding.ToString(); AForge.Imaging.Filters.Threshold thf = new AForge.Imaging.Filters.Threshold(thresholding); Bitmap ther = thf.Apply(image); BlobCounter blobCounter = new BlobCounter(ther); Blob[] blobs = blobCounter.GetObjects(ther, false); ImageStatistics img; AForge.Imaging.Filters.GrayscaleToRGB d1 = new GrayscaleToRGB(); Bitmap bm = d1.Apply(image); Edges s = new Edges(); Graphics gg = Graphics.FromImage(bm); string ss = null; Bitmap myImage = null; Blob b; int count = 0; listView1.Items.Clear(); mylesions.Clear(); Crop cut; Bitmap Ilesion = null; //System.Threading.Tasks.Parallel.ForEach(blobs, blob => foreach (Blob blob in blobs) { img = new ImageStatistics(blob.Image); double perc = ((double)img.PixelsCountWithoutBlack / (double)img.PixelsCount) * 100; textBox2.Text = perc.ToString(); if (blob.Image.Size.Height > 20 && blob.Image.Size.Width > 20 && perc > 35) { b = blob; cut = new Crop(b.Rectangle); Ilesion = g1.Apply(cut.Apply(userControl11.bmp)); ImageStatistics st = new ImageStatistics(b.Image); Bitmap pp = s.Apply(b.Image); ChannelFiltering c = new ChannelFiltering(new IntRange(0, 255), new IntRange(0, 0), new IntRange(0, 0)); Bitmap pp2 = d1.Apply(pp); c.ApplyInPlace(pp2); pp2.MakeTransparent(Color.Black); gg.DrawImage(pp2, b.Rectangle); gg.Flush(); myImage = userControl11.bmp.Clone(b.Rectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb); ss = ((double)(st.PixelsCountWithoutBlack) * (double)dd.pixelHeight * dd.pixelWidth).ToString(); ListViewItem lv = new ListViewItem(count.ToString()); lv.SubItems.Add(ss); lv.SubItems.Add(b.Rectangle.Location.X.ToString() + "," + b.Rectangle.Location.Y.ToString()); listView1.Items.Add(lv); Add adder = new Add(pp); Bitmap undashes = (Bitmap)Ilesion.Clone(); adder.ApplyInPlace(Ilesion); string locc = (b.Rectangle.Location.X * dd.pixelWidth).ToString() + "mm," + (b.Rectangle.Location.Y * dd.pixelHeight).ToString() + "mm"; mylesions.Add(new lesion((Bitmap)Ilesion.Clone(), ss, b.Rectangle.Location, locc, undashes)); count++; } } textBox1.Text = "tumor size= " + ss + " mm² *" + dd.pixelDepth.ToString() + "mm"; // host.NewDocument(bmp); // pictureBox2.Image = myImage; pictureBox1.Image = bm; pictureBox2.Image = Ilesion; } else { pictureBox1.Image = userControl11.bmp; } pictureBox1.Invalidate(); } //userControl11.increasecontrast(200); } else { if (dd.dicmFound == false) { MessageBox.Show("This does not seem to be a DICOM 3.0 file. Sorry, I can't open this."); } else if (dd.dicomDir == true) { MessageBox.Show("This seems to be a DICOMDIR file, and does not contain an image."); } else { MessageBox.Show("Sorry, I can't read a DICOM file with this Transfer Syntax\n" + "You may view the initial tags instead."); } //userControl11.SetParameters(ref pixels8, imageWidth, imageHeight, // winWidth, winCentre, true, this); } }