public static Bitmap thin(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 파일 경로 DocumentAnalysis.IniUtil ini = new DocumentAnalysis.IniUtil(filePath); // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌) //////////// ini 객체 생성 끝 ///////////////////////////////////////////////////////// int order = int.Parse(ini.GetIniValue("선굵기값", "가늘게횟수")); for (int i = 0; i < order; i++) { Bitmap tmp = (Bitmap)source; // 중요! 한번 이미지 처리가 끝난 비트맵 source 는 clone 함수로 보내기 전에 다시 한번 (Bitmap) 처리 해줘야함, 이유는 잘 모르겠음 // convert to 24 bits per pixel source = imageProcess.Clone(tmp, PixelFormat.Format24bppRgb); // delete old image tmp.Dispose(); Dilatation filter = new Dilatation(); filter.ApplyInPlace(source); } return(source); }
public Bitmap Dilatation(Bitmap bitmap) { var bmp = ReverseBitmapColors(bitmap); Dilatation filter = new Dilatation(); filter.ApplyInPlace(bmp); return(ReverseBitmapColors(bmp)); }
/// <summary> /// Creates a comic rendered copy of the input image. /// </summary> public override Bitmap Render(Bitmap sourceImage) { GrayscaleToRGB convertColor = new GrayscaleToRGB(); if (sourceImage.PixelFormat == PixelFormat.Format8bppIndexed) { sourceImage = convertColor.Apply(sourceImage); } BilateralBlur blur = new BilateralBlur(3, 0.1); Bitmap comic = blur.Apply(sourceImage); // Edges Bitmap grayscale = Grayscale.CommonAlgorithms.Y.Apply(comic); SobelEdgeDetector sobelEdge = new SobelEdgeDetector(); sobelEdge.ScaleIntensity = true; Bitmap edgeLayer = sobelEdge.Apply(grayscale); edgeLayer = convertColor.Apply(edgeLayer); Invert invertEdge = new Invert(); invertEdge.ApplyInPlace(edgeLayer); HSLLinear edgeLinear = new HSLLinear(); edgeLinear.InLuminance.Min = 0; edgeLinear.InLuminance.Max = 0.8; edgeLinear.ApplyInPlace(edgeLayer); // highlights Bitmap highlightLayer = invertEdge.Apply(edgeLayer); Dilatation highlightDilitation = new Dilatation(); highlightDilitation.ApplyInPlace(highlightLayer); BrightnessCorrection highlightBright = new BrightnessCorrection(-0.35); highlightBright.ApplyInPlace(highlightLayer); ColorDodge highlightBlend = new ColorDodge(highlightLayer); highlightBlend.ApplyInPlace(comic); // Merge edges with working layer Multiply multEdge = new Multiply(edgeLayer); multEdge.ApplyInPlace(comic); return(comic); }
void DilasiToolStripMenuItemClick(object sender, EventArgs e) { //jika gambar kosong/null maka akan mengembalikan nilai kosong/null if (gambar == null) { return; } //membuat filter dari inisiasi class Dilatation() pada objek dilatation Dilatation dilatation = new Dilatation( ); //clone variable gambar pada variable gambar2 gambar2 = (Bitmap)gambar.Clone(); //aplikasikan filter objek dilatation pada gambar2 dilatation.ApplyInPlace(gambar2); //tampilkan hasil gambar2 yang sudah diaplikasikan filter pada pictureBox2 pictureBox2.Image = gambar2; }
/// <summary> /// This method binarize dnd dilate image. /// </summary> /// <param name="image"></param> /// <returns></returns> private Bitmap BinarizeAndDilationWithMedian(Bitmap image) { int[,] kernel = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; // create filter Convolution Convolution = new Convolution(kernel); // apply the filter Convolution.ApplyInPlace(image); var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image); Invert invert = new Invert(); invert.ApplyInPlace(bmp8bpp); Dilatation dilatation = new Dilatation(); dilatation.ApplyInPlace(bmp8bpp); invert.ApplyInPlace(bmp8bpp); Median median = new Median(); median.ApplyInPlace(bmp8bpp); Closing closing = new Closing(); closing.ApplyInPlace(bmp8bpp); OtsuThreshold OtsuThreshold = new OtsuThreshold(); OtsuThreshold.ApplyInPlace(bmp8bpp); //bmp8bpp.Save(@"C:\Users\Maor\Desktop\mode\BinarizeAndDilationWithMedian.jpeg"); return(bmp8bpp); }
public Binarize(UISettings ui, FileData file) : base(ui, file) { try { Invert AFinvert = new Invert(); switch (ui.ThresholdIndex) // threshold method selection "Global mean" / "Local adaptive" { case 0: // Global if (ui.ThreshGlobalIsAbsolute) // use absolute { Threshold AFglobalbinary = new Threshold(ui.ThreshGlobalAbsolute); UnmanagedBlackWhite = AFglobalbinary.Apply(UnmanagedGray); } else // use relative { ImageStatistics stats = new ImageStatistics(UnmanagedGray, AFinvert.Apply(UnmanagedExclude)); Threshold AFglobalbinary = new Threshold(stats.Gray.Center2QuantileValue(1.0d * ui.ThreshGlobalRelative / 255.0d)); UnmanagedBlackWhite = AFglobalbinary.Apply(UnmanagedGray); } break; case 1: // Local BradleyLocalThresholdingX AFlocalbinary = new BradleyLocalThresholdingX() { PixelBrightnessDifferenceLimit = ui.ThreshLocalBrightnessDifference, WindowSize = ui.ThreshLocalWindowSize, UpperLimit = 250 }; UnmanagedBlackWhite = AFlocalbinary.Apply(UnmanagedGray); break; } if (ui.FillHoleAirspaceSwitch && ui.FillHoleAirspace != 0) // fill holes of airspaces { FillHoles AFfillinair = new FillHoles() { CoupledSizeFiltering = true, MaxHoleHeight = ui.FillHoleAirspace, MaxHoleWidth = ui.FillHoleAirspace }; //FillHolesArea AFfillinair=new FillHolesArea() { MaxHoleArea=ui.FillHoleAirspace }; AFfillinair.ApplyInPlace(UnmanagedBlackWhite); } UnmanagedBlackWhite = AFinvert.Apply(UnmanagedBlackWhite); if (ui.FillHoleTissueSwitch && ui.FillHoleTissue != 0) // fill holes of tissue { FillHoles AFfillintissue = new FillHoles() { CoupledSizeFiltering = true, MaxHoleHeight = ui.FillHoleTissue, MaxHoleWidth = ui.FillHoleTissue }; //FillHolesArea AFfillintissue=new FillHolesArea() { MaxHoleArea=ui.FillHoleTissue }; AFfillintissue.ApplyInPlace(UnmanagedBlackWhite); } if (ui.MorphoDilateSwitch && ui.MorphoDilate != 0) // Morphological Dilate { int n = (Math.Max(ui.MorphoDilate, 0) * 2 + 1); short[,] morphmatrix = new short[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { morphmatrix[i, j] = 1; } } Dilatation AFdilate = new Dilatation(morphmatrix); AFdilate.ApplyInPlace(UnmanagedBlackWhite); } if (ui.MorphoErodeSwitch && ui.MorphoErode != 0) // Morphological Erode { int n = (Math.Max(ui.MorphoErode, 0) * 2 + 1); short[,] morphmatrix = new short[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { morphmatrix[i, j] = 1; } } Erosion AFerode = new Erosion(morphmatrix); AFerode.ApplyInPlace(UnmanagedBlackWhite); } if (ui.ExcludeColorSwitch) { NonParen_SumArea = ui.um2px2 * UnmanagedExclude.NonBlackArea(); } if (ui.BlobMinSwitch) { Low_Threshold = Math.Pow(10.0d, ui.BlobMin) - 1; } else { Low_Threshold = 0.0d; } if (ui.BlobMaxSwitch) { High_Threshold = Math.Pow(10.0d, ui.BlobMax) - 1; } else { High_Threshold = int.MaxValue; } if (ui.BlobMinSwitch || ui.BlobMaxSwitch) { Merge AFmerge1 = new Merge(UnmanagedExclude); ExcludeSize AFexcsize = new ExcludeSize() { Low = (int)Math.Round(Low_Threshold / ui.um2px2), High = (int)Math.Round(Math.Min(int.MaxValue, High_Threshold / ui.um2px2)) }; Merge AFmerge2 = new Merge(AFexcsize.Apply(AFinvert.Apply(AFmerge1.Apply(UnmanagedBlackWhite)))); AFmerge2.ApplyInPlace(UnmanagedExclude); Low_SumArea = ui.um2px2 * AFexcsize.LowCount; High_SumArea = ui.um2px2 * AFexcsize.HighCount; } } catch { throw new Exception("Error Occured During Binarization"); } }
private void Button_HSV_Filter_Click(object sender, EventArgs e) { Bitmap image = new Bitmap(pictureBox1.Image); HSLFiltering filterHsl = new HSLFiltering(); Mean filterMean = new Mean(); filterHsl.Luminance = new AForge.Range(0.1f, 1); filterHsl.UpdateHue = false; filterHsl.UpdateSaturation = false; filterHsl.UpdateLuminance = true; filterHsl.ApplyInPlace(image); filterMean.ApplyInPlace(image); SISThreshold filterThresold = new SISThreshold(); GrayscaleBT709 filterGray = new GrayscaleBT709(); image = filterGray.Apply(image); Bitmap clone = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format8bppIndexed); filterThresold.ApplyInPlace(clone); image = clone; Bitmap clone2normal = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format32bppRgb); image = clone2normal; BlobCounter bc = new BlobCounter(); bc.FilterBlobs = true; bc.MinWidth = 5; bc.MinHeight = 5; bc.ProcessImage(image); Blob[] blobs = bc.GetObjects(image, false); var rectanglesToClear = from blob in blobs select blob.Rectangle; using (var gfx = Graphics.FromImage(image)) { foreach (var rect in rectanglesToClear) { if (rect.Height < 20 && rect.Width < 20) { gfx.FillRectangle(Brushes.White, rect); } } gfx.Flush(); } Dilatation filterDilation = new Dilatation(); image = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format48bppRgb); filterDilation.ApplyInPlace(image); filterDilation.ApplyInPlace(image); Erosion filterErosion = new Erosion(); filterErosion.ApplyInPlace(image); pictureBox2.Image = image; }
/// <summary> /// Apply - search for broken bones - by finding lines and detecting angles between them /// </summary> /// <param name="bmp">Bitmap - original</param> /// <returns>Bitmap - processed</returns> public Bitmap Apply(Bitmap bmp) { System.Drawing.Imaging.PixelFormat pf = bmp.PixelFormat; ROI = bmp.Rectangle(); var lineTransform = new AForge.Imaging.HoughLineTransformation(); lineTransform.MinLineIntensity = 60; lineTransform.LocalPeakRadius = 15; //lineTransform.StepsPerDegree = 10; //lineTransform.LocalPeakRadius = 10; // apply Hough line transofrm lineTransform.ProcessImage(bmp); Bitmap houghLineImage = lineTransform.ToBitmap(); // get lines using relative intensity var lines = lineTransform.GetLinesByRelativeIntensity(0.5); lines = filterLinesByTheta(lines); Dilatation dl = new Dilatation(); dl.ApplyInPlace(bmp); Invert filter = new Invert(); filter.ApplyInPlace(bmp); bmp = bmp.Bit8ToBit24(); foreach (var line in lines) { // get line's radius and theta values int radius = line.Radius; double lineSlopeInDegrees = line.Theta; // check if line is in lower part of the image if (radius < 0) { lineSlopeInDegrees += 180; radius = -radius; } var radians = lineSlopeInDegrees.DegreesToRadians(); var imageCenter = bmp.GetCenter(); double x0 = 0, //most left point y0 = 0, x1 = 0, //most right point y1 = 0; if (line.Theta != 0) { // none-vertical line x0 = -imageCenter.X; // most left point x1 = imageCenter.X; // most right point // calculate corresponding y values y0 = (-radians.Cosinus() * x0 + radius) / radians.Sinus(); y1 = (-radians.Cosinus() * x1 + radius) / radians.Sinus(); } else { // vertical line x0 = line.Radius; x1 = line.Radius; y0 = imageCenter.Y; y1 = -imageCenter.Y; } var line2 = new Line( (int)x0 + imageCenter.X, imageCenter.Y - (int)y0, (int)x1 + imageCenter.X, imageCenter.Y - (int)y1); line2.X1 = (int)x0 + imageCenter.X; line2.Y1 = imageCenter.Y - (int)y0; line2.X2 = (int)x1 + imageCenter.X; line2.Y2 = imageCenter.Y - (int)y1; Lines.Add(line2); } return(drawLines(bmp)); }