/// <summary> /// Convert image to color space of known stain. /// </summary> /// <param name="source">Source image.</param> /// <param name="stain">Known stain.</param> /// <param name="channel">Channel of stain. Takes int 0-2.</param> /// <returns>Color deconvoluted image.</returns> public static Bitmap ColorDeconvolution(Bitmap source, ColorDeconvolution.KnownStain stain, int channel) { using (var image = source.Clone() as Bitmap) { BitmapProcessor bitmapProcessor = new BitmapProcessor(source); ColorDeconvolution colorDeconvolution = new ColorDeconvolution(); GrayscaleProcessor gpDeconvoluted = null; if (channel == 0) { gpDeconvoluted = colorDeconvolution.Get1stStain(bitmapProcessor, stain); } else if (channel == 1) { gpDeconvoluted = colorDeconvolution.Get2ndStain(bitmapProcessor, stain); } else if (channel == 2) { gpDeconvoluted = colorDeconvolution.Get3rdStain(bitmapProcessor, stain); } else { return(null); } Bitmap result = gpDeconvoluted.Bitmap.Clone() as Bitmap; gpDeconvoluted.Dispose(); return(result); } }
private IEnumerable <Tuple <Bitmap, string, int> > process() { using (var source = this.DisplayedImage.Clone() as Bitmap){ var gspR = new GrayscaleProcessor(source.Clone() as Bitmap, RgbToGrayscaleConversion.JustReds); gspR.Dispose(); yield return(Tuple.Create(gspR.Bitmap, "Red", 128)); var gpDAB = new ColorDeconvolution().Get2ndStain(source, ColorDeconvolution.KnownStain.HaematoxylinDAB); gpDAB.Dispose(); yield return(Tuple.Create(gpDAB.Bitmap, "DAB", 128)); } }
private void PerformImageAnalysis() { if (WsiComposite.Tile.WsiBox.Image == null) return; GrayscaleProcessor p = new GrayscaleProcessor(WsiComposite.Tile.WsiBox.Image, RgbToGrayscaleConversion.Mean); p.WriteBack = false; ObjectLayer layer = new ThresholdSegmentation().Execute(p); p.Dispose(); WsiComposite.Tile.WsiBox.ObjectLayer = layer; }
public static IResult <bool> Execute(Bitmap image) { var r = new Result <bool>(); using (var source = image.Clone() as Bitmap){ var gspR = new GrayscaleProcessor(source.Clone() as Bitmap, RgbToGrayscaleConversion.JustReds); gspR.Dispose(); r.DebugBitmaps.Add(Tuple.Create(gspR.Bitmap, "Red")); r.DebugLayers.Add(createLayer(gspR.Bitmap, RedThreshold, "Red")); r.DebugVariables.Add("RedThreshold", RedThreshold); var gpDAB = new SharpAccessory.Imaging.Filters.ColorDeconvolution().Get2ndStain(source, SharpAccessory.Imaging.Filters.ColorDeconvolution.KnownStain.HaematoxylinDAB); gpDAB.Dispose(); r.DebugBitmaps.Add(Tuple.Create(gpDAB.Bitmap, "DAB")); var dabLayer = createLayer(gpDAB.Bitmap, DabThreshold, "DAB"); r.DebugLayers.Add(dabLayer); r.DebugVariables.Add("DabThreshold", DabThreshold); r.Value = 0 < dabLayer.Objects.Count; } return(r); }
public override ProcessResult Execute(ProcessExecutionParams p) { GrayscaleProcessor gpH = new ColorDeconvolution().Get1stStain(p.Bitmap, ColorDeconvolution.KnownStain.HaematoxylinEosin); GrayscaleProcessor gp = new GrayscaleProcessor(p.Bitmap, RgbToGrayscaleConversion.JustReds); GrayscaleProcessor gpSobel = (GrayscaleProcessor)gp.Clone(); new MeanFilter().Execute(gp, new Size(3, 3)); new SobelEdgeDetector().Execute(gpSobel); new MinimumFilter().Execute(gpH, new Size(3, 3)); new PixelInverter().Execute(gpH); ObjectLayer l1stLevel = this.Execute1stLevelSegmentation(gp, gpSobel, gpH); float targetArea = this.GetTargetArea(l1stLevel); ObjectLayer l2ndLevel = this.Execute2ndLevelSegmentation(gp, gpSobel, gpH, targetArea); ObjectLayer l3rdLevel = this.Execute3rdLevelSegmentation(l2ndLevel, gpSobel, gpH, targetArea); gpSobel.WriteBack = false; gpH.WriteBack = false; gp.WriteBack = false; gpSobel.Dispose(); gpH.Dispose(); gp.Dispose(); gpSobel.Bitmap.Dispose(); gpH.Bitmap.Dispose(); l3rdLevel.Name = "Image Analysis"; return new ProcessResult(new ObjectLayer[] { l3rdLevel }); }
public override ProcessResult Execute(ProcessExecutionParams p) { GrayscaleProcessor gpH = new ColorDeconvolution().Get1stStain(p.Bitmap, ColorDeconvolution.KnownStain.HaematoxylinEosin); GrayscaleProcessor gp = new GrayscaleProcessor(p.Bitmap, RgbToGrayscaleConversion.JustReds); GrayscaleProcessor gpSobel = (GrayscaleProcessor)gp.Clone(); new MeanFilter().Execute(gp, new Size(3, 3)); new SobelEdgeDetector().Execute(gpSobel); new MinimumFilter().Execute(gpH, new Size(3, 3)); new PixelInverter().Execute(gpH); ObjectLayer l1stLevel = this.Execute1stLevelSegmentation(gp, gpSobel, gpH); float targetArea = this.GetTargetArea(l1stLevel); ObjectLayer l2ndLevel = this.Execute2ndLevelSegmentation(gp, gpSobel, gpH, targetArea); ObjectLayer l3rdLevel = this.Execute3rdLevelSegmentation(l2ndLevel, gpSobel, gpH, targetArea); gpSobel.WriteBack = false; gpH.WriteBack = false; gp.WriteBack = false; gpSobel.Dispose(); gpH.Dispose(); gp.Dispose(); gpSobel.Bitmap.Dispose(); gpH.Bitmap.Dispose(); l3rdLevel.Name = "Image Analysis"; return(new ProcessResult(new ObjectLayer[] { l3rdLevel })); }
public override ProcessResult Execute(ProcessExecutionParams p) { GrayscaleProcessor gp = new GrayscaleProcessor(new Bitmap(p.Bitmap), RgbToGrayscaleConversion.None); BitmapProcessor bp = new BitmapProcessor(p.Bitmap.Clone() as Bitmap); for (int dy = 0; dy < gp.Height; dy++) { for (int dx = 0; dx < gp.Width; dx++) { int pixel = (int)bp.GetPixel(dx, dy); int r = (pixel & 0x00ff0000) >> 16; int g = (pixel & 0x0000ff00) >> 08; int b = (pixel & 0x000000ff) >> 00; int max = Math.Max(Math.Max(r, g), b); int min = Math.Min(Math.Min(r, g), b); int range = max - min; int level = (r + g + b) / 3; int val = level - range; if (val > 255) { val = 255; } if (val < 0) { val = 0; } gp.SetPixel(dx, dy, (UInt32)level); } } GrayscaleProcessor gpSobel = (GrayscaleProcessor)gp.Clone(); new SobelEdgeDetector().Execute(gpSobel); ObjectLayer l1stLevel = Execute1stLevelSegmentation(gp, gpSobel); ObjectLayer l2ndLevel = Execute2ndLevelSegmentation(l1stLevel, gp); gpSobel.WriteBack = false; gp.WriteBack = false; gpSobel.Dispose(); gp.Dispose(); bp.Dispose(); gpSobel.Bitmap.Dispose(); gp.Bitmap.Dispose(); bp.Bitmap.Dispose(); l1stLevel.Name = "1st Level"; l2ndLevel.Name = "2nd Level"; return(new ProcessResult(new ObjectLayer[] { l1stLevel, l2ndLevel })); }