Пример #1
0
        public void RangeUnspecified_SetMinAddValue_BecomesValidWithMatchingMinAndMax()
        {
            var range = new Range <int>();

            range.Minimum = 5;
            range.Add(4);
            Assert.Equal(4, range.Minimum);
            Assert.Equal(4, range.Maximum);
            Assert.True(range.IsValid);
        }
Пример #2
0
        private Range <TPosition> GetRange(IEnumerable <Range <IComparable> > ranges)
        {
            Range <TPosition> range1 = new Range <TPosition>();

            foreach (Range <IComparable> range2 in ranges)
            {
                if (range2.HasData)
                {
                    Range <TPosition> range3 = new Range <TPosition>(this.ConvertToPositionType((object)range2.Minimum), this.ConvertToPositionType((object)range2.Maximum));
                    range1 = range1.Add(range3);
                }
            }
            return(range1);
        }
Пример #3
0
            public static Range Import(string fname)
            {
                if (!File.Exists(fname))
                {
                    return(null);
                }

                using (StreamReader sr = new StreamReader(fname, Encoding.Default, true))
                {
                    //сохраненеи заголовка
                    List <string> header = new List <string>();
                    string[]      heads  = sr.ReadLine().Split(';');
                    for (int i = 0; i < heads.Length - 3; i++)
                    {
                        header.Add(heads[3 + i]);
                    }


                    //чтение файла
                    Range res = new Range()
                    {
                        header = header
                    };
                    while (!sr.EndOfStream)
                    {
                        string   line = sr.ReadLine();
                        string[] arr  = line.Split(';');

                        //получение даты
                        bool isdate =
                            int.TryParse(arr[0], out int month) &
                            int.TryParse(arr[1], out int day) &
                            int.TryParse(arr[2], out int hour);

                        if (!isdate) //выход, если не удалось получить дату
                        {
                            continue;
                        }

                        DateTime key = new DateTime(1, month, day, hour - 1, 0, 0);

                        //сохранение данных
                        List <double> vals = new List <double>();
                        for (int i = 3; i < arr.Length; i++) //первый три столбца это месяц, день, час. остальные -- данные
                        {
                            bool isval = double.TryParse(arr[i].Replace('.', Constants.DecimalSeparator), out double val);
                            vals.Add(isval ? val : double.NaN);
                        }

                        if (!res.ContainsKey(key))
                        {
                            res.Add(key, new Item()
                            {
                                Date = key, Values = vals
                            });
                        }
                    }
                    res.FileName = Path.GetFileNameWithoutExtension(fname);
                    return(res);
                }
            }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
              this.CreateTabContainer("StromaDetection");
              this.TabContainer.Enabled = true;

              (new Button
              {
            Text = "execute cell core segmentation",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            if (null == this.DisplayedImage) return;
            ProcessResult result = null;
            var progressDialog = new ProgressDialog { Message = "executing cell core segmentation", ProgressBarStyle = ProgressBarStyle.Marquee, AllowCancel = false };
            progressDialog.BackgroundTask += () =>
            {
              var segmentation = new CellCoreSegmentation();
              var executionParams = new ProcessExecutionParams(this.DisplayedImage);
              result = segmentation.Execute(executionParams);
            };
            progressDialog.CenterToScreen();
            progressDialog.ShowDialog();
            this.SetLayers(result.Layers.ToArray());
              };

              (new Button
              {
            Text = "execute threshold segmentation",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            if (null == this.DisplayedImage) return;
            var m = new Map(this.DisplayedImage.Width, this.DisplayedImage.Height);
            using (var gp = new GrayscaleProcessor(this.DisplayedImage.Clone() as Bitmap, RgbToGrayscaleConversion.Mean))
            {
              for (var x = 0; x < this.DisplayedImage.Width; x++)
              {
            for (var y = 0; y < this.DisplayedImage.Height; y++)
            {
              m[x, y] = gp.GetPixel(x, y) < this.threshold.Value ? 1u : 0u;
            }
              }
            }
            var layer = new ConnectedComponentCollector().Execute(m);
            layer.Name = "threshold " + this.threshold.Value + " segmentation";
            var layers = this.GetLayers().ToList();
            layers.Add(layer);
            this.SetLayers(layers.ToArray());
              };

              this.threshold = new NumericUpDown
              {
            Parent = new GroupBox
            {
              Parent = this.TabContainer,
              Dock = DockStyle.Top,
              Text = "threshold",
              Height = 40
            },
            Dock = DockStyle.Fill,
            Minimum = 0,
            Maximum = 255,
            Increment = 16,
            Value = 128,
            DecimalPlaces = 0
              };

              (new Button
              {
            Text = "display edges",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            this.SetDisplayedImage(this.edges);
              };

              (new Button
              {
            Text = "execute edge detection",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            if (null == this.stainH || null == this.stainE) return;
            this.responseH = Filtering.ExecuteSobel(this.stainH);
            this.responseE = Filtering.ExecuteSobel(this.stainE);
            var substracted = new double[this.responseH.Size.Width, this.responseH.Size.Height];
            var substractedRange = new Range<double>();
            for (var x = 0; x < this.responseH.Size.Width; x++)
            {
              for (var y = 0; y < this.responseH.Size.Height; y++)
              {
            var value = Math.Max(0, this.responseE.Gradient[x, y] - this.responseH.Gradient[x, y]);
            substracted[x, y] = value;
            substractedRange.Add(value);
              }
            }
            this.nonMaximumSupression = Filtering.ExecuteNonMaximumSupression(substracted, this.responseE.Orientation);
            this.edges = Visualization.Visualize(this.nonMaximumSupression, Visualization.CreateColorizing(substractedRange.Maximum));
            this.SetDisplayedImage(this.edges);
              };

              (new Button
              {
            Text = "display haematoxylin",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            this.SetDisplayedImage(this.stainH);
              };

              (new Button {
            Text = "display eosin",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            this.SetDisplayedImage(this.stainE);
              };

              (new Button {
            Text = "display source",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            this.SetDisplayedImage(this.source);
              };

              (new Button {
            Text = "execute deconvolution",
            Parent = this.TabContainer,
            Dock = DockStyle.Top
              }).Click += delegate
              {
            if (null == this.DisplayedImage) return;
            this.source = this.DisplayedImage;
            var gpE = new ColorDeconvolution().Get2ndStain(this.DisplayedImage, ColorDeconvolution.KnownStain.HaematoxylinEosin);
            gpE.Dispose();
            this.stainE = gpE.Bitmap;
            var gpH = new ColorDeconvolution().Get1stStain(this.DisplayedImage, ColorDeconvolution.KnownStain.HaematoxylinEosin);
            gpH.Dispose();
            this.stainH = gpH.Bitmap;
            this.SetDisplayedImage(this.stainE);
              };
        }
Пример #5
0
 public void setRange(double start, double end)
 {
     Range.Add(start);
     Range.Add(end);
 }
Пример #6
0
        /*
         * Parses data
         */
        public static void Init(String inpF)
        {
            //Read data from file
            List <string> data = new List <string>();

            using (var reader = new StreamReader(inpF))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    data.Add(line);
                }
            }

            //Parse each line
            foreach (var item in data)
            {
                Console.WriteLine(item);
                var line = item.Split(',');

                switch (line[0])
                {
                case "LidarAngles":
                    // Read in Lidar Properties
                    List <double> LidarAngles = new List <double>();
                    for (int i = 1; i < line.Length; i++)
                    {
                        LidarAngles.Add(double.Parse(line[i]));
                    }

                    // Convert to unit vectors rQBb
                    rQBb = Matrix <double> .Build.Dense(2, LidarAngles.Count);

                    for (int i = 0; i < rQBb.ColumnCount; i++)
                    {
                        rQBb[0, i] = Math.Cos(LidarAngles[i]);
                        rQBb[1, i] = Math.Sin(LidarAngles[i]);
                    }
                    break;

                case "LidarMaxRange":
                    MaxRange = double.Parse(line[1]);
                    break;

                case "ODOM":

                    double[] tmp = { double.Parse(line[1]),
                                     double.Parse(line[2]),
                                     double.Parse(line[3]) };

                    Pose.Add(tmp);
                    break;

                case "Lidar":
                    List <double> _ranges = new List <double>();
                    for (int i = 1; i < line.Length; i++)
                    {
                        _ranges.Add(double.Parse(line[i]));
                    }
                    Range.Add(_ranges);
                    break;

                default:
                    break;
                }
            }//endfor
        }
Пример #7
0
        private static void Main(string[] args)
        {
            foreach (var slideName in Util.GetSlideFilenames(args))
            {
                using (var slideCache = new SlideCache(slideName)){
                    var scale    = 0.5f;
                    var tileSize = 500;
                    var slidePartitionerFileName = slideCache.DataPath + "BudDetection.Buds.xml";
                    var slidePartitioner         = File.Exists(slidePartitionerFileName)?SlidePartitioner <int?>
                                                   .Load(slidePartitionerFileName):new SlidePartitioner <int?>(slideCache.Slide, scale, new Size(tileSize, tileSize));

                    var heatMapHelper = new HeatMapHelper(slideCache.GetImage("tissueHeatMap"));
                    var budCountRange = new Range <int>();

                    foreach (var tile in slidePartitioner.Values)
                    {
                        if (tile.Data.HasValue)
                        {
                            Console.WriteLine(slideCache.SlideName + "-" + tile.Index + ":" + tile.Data.Value + " skipped");
                            budCountRange.Add(tile.Data.Value);
                            continue;
                        }

                        var colors = heatMapHelper.GetAffectedColors(slideCache.Slide.Size, tile.SourceArea);
                        var values = heatMapHelper.GetAffectedValues(slideCache.Slide.Size, tile.SourceArea);
                        if (values.All(v => 0 != v))
                        {
                            Console.WriteLine(slideCache.SlideName + "-" + tile.Index + ": no tissue");
                            continue;
                        }

                        using (var tileImage = slideCache.Slide.GetImagePart(tile)){
                            if (false)
                            {
                                var tileCache = slideCache.GetTileCache(tile.Index);
                                tileCache.SetImage("rgb", tileImage);                               //speichert unter C:\ProgramData\processingRepository\[slideCache.SlideName]\[Index]\... ansonsten tileImage.Save("[uri].png")
                            }
                            var r = BudDetection.Detector.Execute(tileImage);
                            //var r = ColorDeconvolution.Detect(tileImage);
                            var layer = r.Value;
                            tile.Data = layer.Objects.Count;
                            budCountRange.Add(layer.Objects.Count);
                            foreach (var io in layer.Objects)
                            {
                                //var bb=io.Contour.FindBoundingBox();
                                var offset       = tile.SourceArea.Location;
                                var sourcePoints = new List <Point>();
                                foreach (var contourPoint in io.Contour.GetPoints())
                                {
                                    double x           = Math.Round(contourPoint.X / scale + offset.X);
                                    double y           = Math.Round(contourPoint.Y / scale + offset.Y);
                                    var    sourcePoint = new Point((int)x, (int)y);
                                    sourcePoints.Add(sourcePoint);
                                }
                                var annotation = slideCache.Slide.CreateAnnotation(AnnotationType.PolygonLine);
                                foreach (var point in sourcePoints)
                                {
                                    annotation.AppendPoints(point);
                                }
                                annotation.Color = Color.OrangeRed;
                                annotation.Name  = null == io.Class?"bud":io.Class.Name;
                            }
                        }
                        Console.WriteLine(slideCache.SlideName + "-" + tile.Index + " done");
                        if (Console.KeyAvailable)
                        {
                            break;
                        }
                    }
                    slidePartitioner.Save(slidePartitionerFileName);
                    using (var heatMap = slidePartitioner.GenerateHeatMap(b => {
                        if (!b.HasValue)
                        {
                            return(Color.LightSeaGreen);
                        }
                        var c = (int)Math.Round(budCountRange.Normalize(b.Value) * 255d);
                        return(Color.FromArgb(c, c, c));
                    }))
                        slideCache.SetImage("budHeatMap", heatMap);
                }
            }
        }
        private static void Main(string[] args)
        {
            #region init
              if (0 == args.Length)
              {
            Console.WriteLine("no slide name");
            return;
              }
              var slideName = args[0];
              var processinHelper = new Processing(slideName);
              var slide = processinHelper.Slide;
              #endregion init

              TiledProcessInformation<uint[]> haematoxylinHistogram;
              TiledProcessInformation<uint[]> eosinHistogram;

              if (!File.Exists(processinHelper.DataPath + "haematoxylinHistogram.tpi") || !File.Exists(processinHelper.DataPath + "eosinHistogram.tpi"))
              {
            if (!Directory.Exists(processinHelper.DataPath + "deconvolution")) Directory.CreateDirectory(processinHelper.DataPath + "deconvolution");
            var tissueData = TiledProcessInformation<bool>.FromFile(processinHelper.DataPath + "tissueData.tpi");
            haematoxylinHistogram = new TiledProcessInformation<uint[]>(tissueData.Partitioner, tissueData.WsiUri);
            eosinHistogram = new TiledProcessInformation<uint[]>(tissueData.Partitioner, tissueData.WsiUri);
            var partitioner = tissueData.Partitioner;
            var dict = new Dictionary<Point, WsiRect>();
            foreach (var tile in tissueData.Partitioner)
              dict.Add(tissueData.Partitioner.CurrentIndices, tile);
            var stopwatch = new Stopwatch();
            foreach (var tile in partitioner)
            {
              var tissueTile = dict[partitioner.CurrentIndices];
              if (!tissueData[tissueTile]) continue;
              stopwatch.Start();
              using (var tileImage = slide.GetImagePart(tile))
              {
            var hHistogramValue = new uint[256];
            var hValues = new List<double>();
            using (var gpH = new ColorDeconvolution().Get1stStain(tileImage, ColorDeconvolution.KnownStain.HaematoxylinEosin))
            {
              foreach (var intensity in gpH.GetPixels())
              {
                hHistogramValue[intensity]++;
                hValues.Add(intensity);
              }
              haematoxylinHistogram.AddDataToCurrentTile(hHistogramValue);
              gpH.Dispose();
              gpH.Bitmap.Save(processinHelper.DataPath + "deconvolution\\" + partitioner.CurrentIndices + ".h.png");
            }
            var eHistogramValue = new uint[256];
            var eValues = new List<double>();
            using (var gpE = new ColorDeconvolution().Get2ndStain(tileImage, ColorDeconvolution.KnownStain.HaematoxylinEosin))
            {
              foreach (var intensity in gpE.GetPixels())
              {
                eHistogramValue[intensity]++;
                eValues.Add(intensity);
              }
              eosinHistogram.AddDataToCurrentTile(eHistogramValue);
              gpE.Dispose();
              gpE.Bitmap.Save(processinHelper.DataPath + "deconvolution\\" + partitioner.CurrentIndices + ".e.png");
            }
            NumericVector hHistogram = RConnector.Engine.CreateNumericVector(hValues);
            RConnector.Engine.SetSymbol("hHistogram", hHistogram);
            NumericVector eHistogram = RConnector.Engine.CreateNumericVector(eValues);
            RConnector.Engine.SetSymbol("eHistogram", eHistogram);
            var handle = RConnector.StartOutput();
            RConnector.Engine.Evaluate("hist(eHistogram, col=rgb(1,0,0,0.5),xlim=c(0,255), main=\"" + partitioner.CurrentIndices + "\", xlab=\"HE\")");
            RConnector.Engine.Evaluate("hist(hHistogram, col=rgb(0,0,1,0.5), add=T)");
            var output = RConnector.EndOutput(handle);
            output.Save(processinHelper.DataPath + "deconvolution\\histogram" + partitioner.CurrentIndices + ".png");
              }
              stopwatch.Stop();
              Console.WriteLine(partitioner.CurrentIndices + ":" + (stopwatch.ElapsedMilliseconds / 1000d) + "s");
              stopwatch.Reset();
            }
            haematoxylinHistogram.ToFile(processinHelper.DataPath + "haematoxylinHistogram.tpi");
            eosinHistogram.ToFile(processinHelper.DataPath + "eosinHistogram.tpi");
              }
              else
              {
            haematoxylinHistogram = TiledProcessInformation<uint[]>.FromFile(processinHelper.DataPath + "haematoxylinHistogram.tpi");
            eosinHistogram = TiledProcessInformation<uint[]>.FromFile(processinHelper.DataPath + "eosinHistogram.tpi");
              }

              var hRange = new Range<uint>();
              foreach (var tile in haematoxylinHistogram.Partitioner)
              {
            if (null == haematoxylinHistogram[tile]) continue;
            uint sum = 0;
            for (uint i = 0; i < 256; i++)
            {
              sum += haematoxylinHistogram[tile][i] * (255 - i);
            }
            hRange.Add(sum);
              }
              Func<uint[], Color> h2pixel = h =>
              {
            if (null == h) return Color.Gray;
            uint sum = 0;
            for (uint i = 0; i < 256; i++)
            {
              sum += h[i] * (255 - i);
            }
            var ratio = (double)sum / hRange.Maximum;
            return Color.FromArgb(0, 0, (int)Math.Round(255.0 * ratio));
              };
              var eRange = new Range<uint>();
              foreach (var tile in eosinHistogram.Partitioner)
              {
            if (null == eosinHistogram[tile]) continue;
            uint sum = 0;
            for (uint i = 0; i < 256; i++)
            {
              sum += eosinHistogram[tile][i] * (255 - i);
            }
            eRange.Add(sum);
              }
              Func<uint[], Color> e2pixel = e =>
              {
            if (null == e) return Color.Gray;
            uint sum = 0;
            for (uint i = 0; i < 256; i++)
            {
              sum += e[i] * (255 - i);
            }
            var ratio = (double)sum / eRange.Maximum;
            return Color.FromArgb((int)Math.Round(255.0 * ratio), 0, 0);
              };
              using (Bitmap b = haematoxylinHistogram.GenerateHeatMap(h2pixel))
            b.Save(processinHelper.DataPath + "haematoxylinHistogram.png");
              using (Bitmap b = eosinHistogram.GenerateHeatMap(e2pixel))
            b.Save(processinHelper.DataPath + "eosinHistogram.png");
              Console.WriteLine("done");
              Console.ReadKey();
        }
Пример #9
0
        /// <summary>
        /// Updates the actual range displayed on the axis.
        /// </summary>
        private void UpdateActualRange()
        {
            Action action = () =>
            {
                Range<IComparable> dataRange = new Range<IComparable>();
                if (ProtectedMaximum == null || ProtectedMinimum == null)
                {
                    if (Orientation == AxisOrientation.None)
                    {
                        if (ProtectedMinimum != null)
                        {
                            this.ActualRange = OverrideDataRange(new Range<IComparable>(ProtectedMinimum, ProtectedMinimum));
                        }
                        else
                        {
                            this.ActualRange = OverrideDataRange(new Range<IComparable>(ProtectedMaximum, ProtectedMaximum));
                        }
                    }
                    else
                    {
                        IEnumerable<Range<IComparable>> values =
                            this.RegisteredListeners
                                .OfType<IRangeProvider>()
                                .Select(rangeProvider => rangeProvider.GetRange(this));

                        foreach (Range<IComparable> range in values)
                        {
                            dataRange = dataRange.Add(range);
                        }

                        this.ActualRange = OverrideDataRange(dataRange);
                    }
                }
                else
                {
                    this.ActualRange = new Range<IComparable>(ProtectedMinimum, ProtectedMaximum);
                }
            };

            // Repeat this after layout pass.
            if (this.ActualLength == 0.0)
            {
#pragma warning disable 4014
                this.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(action));
#pragma warning restore 4014
            }

            action();
        }
Пример #10
0
        private static void Main(string[] args)
        {
            foreach (var slideName in Util.GetSlideFilenames(args))
            {
                using (var slideCache = new SlideCache(slideName)){
                    // var scale = 0.1f;
                    var scale    = 0.5f; // besser so laut 19.07.2018
                    var tileSize = 100;
                    var slidePartitionerFileName = slideCache.DataPath + "BudDetection.Buds.xml";
                    var slidePartitioner         = File.Exists(slidePartitionerFileName)?SlidePartitioner <int?> .Load(slidePartitionerFileName):new SlidePartitioner <int?>(slideCache.Slide, scale, new Size(tileSize, tileSize));

                    var heatMapHelper = new HeatMapHelper(slideCache.GetImage("tissueHeatMap"));
                    var budCountRange = new Range <int>();
                    var counter       = 0;

                    foreach (var tile in slidePartitioner.Values)
                    {
                        // test, ob schon was für die kackel berechnet wurde
                        if (tile.Data.HasValue)
                        {
                            Console.WriteLine(slideCache.SlideName + "-" + tile.Index + ":" + tile.Data.Value + " skipped");
                            budCountRange.Add(tile.Data.Value);
                            continue;
                        }

                        // soll kachel bearbeitet werden
                        var colors = heatMapHelper.GetAffectedColors(slideCache.Slide.Size, tile.SourceArea);
                        var values = heatMapHelper.GetAffectedValues(slideCache.Slide.Size, tile.SourceArea);
                        if (values.All(v => 255 == v))                      // 255 weiß
                        {
                            Console.WriteLine(slideCache.SlideName + "-" + tile.Index + ": no tissue");
                            continue;
                        }

                        using (var tileImage = slideCache.Slide.GetImagePart(tile)){
                            counter = counter + 1;

                            if (false)
                            {
                                var tileCache = slideCache.GetTileCache(tile.Index);
                                tileCache.SetImage("rgb", tileImage);                               //speichert unter C:\ProgramData\processingRepository\[slideCache.SlideName]\[Index]\... ansonsten tileImage.Save("[uri].png")
                            }

                            var r     = BudDetection.Detector.Execute(tileImage);                         // importent call
                            var layer = r.Value;

                            tile.Data = layer.Objects.Count;
                            budCountRange.Add(layer.Objects.Count);

                            // für alle gefundene objekte wird eine annotation angelegt
                            foreach (var io in layer.Objects)
                            {
                                //var bb=io.Contour.FindBoundingBox();
                                var offset       = tile.SourceArea.Location;
                                var sourcePoints = new List <Point>();
                                foreach (var contourPoint in io.Contour.GetPoints())
                                {
                                    double x           = Math.Round(contourPoint.X / scale + offset.X);
                                    double y           = Math.Round(contourPoint.Y / scale + offset.Y);
                                    var    sourcePoint = new Point((int)x, (int)y);
                                    sourcePoints.Add(sourcePoint);
                                }
                                var annotation = slideCache.Slide.CreateAnnotation(AnnotationType.PolygonLine);
                                foreach (var point in sourcePoints)
                                {
                                    annotation.AppendPoints(point);
                                }
                                annotation.Color = Color.PaleVioletRed;
                                annotation.Name  = null == io.Class?"bud":io.Class.Name;
                            }
                        }
                        if (counter % 100 == 0)
                        {
                            Console.WriteLine(slideCache.SlideName + "-" + tile.Index + " done");
                        }

                        if (Console.KeyAvailable)
                        {
                            break;
                        }
                    }

                    slidePartitioner.Save(slidePartitionerFileName);

                    // normalisierung
                    using (var heatMap = slidePartitioner.GenerateHeatMap(b => {
                        if (!b.HasValue)
                        {
                            return(Color.LightSeaGreen);
                        }
                        var c = (int)Math.Round(budCountRange.Normalize(b.Value) * 255d);
                        return(Color.FromArgb(c, c, c));                      // grauwert(hell == viele butts)
                    }))

                        slideCache.SetImage("budHeatMap", heatMap);
                }
            }
        }
Пример #11
0
        private static void processInput()
        {
            int Radius = 2;
              int NoiseLevel = 10;

              Console.WriteLine("Processing Input...");
              foreach (var import in importItems)
              {
            Console.WriteLine();
            Console.WriteLine(import.FileName);

            Console.WriteLine("Slide extrahieren...");
            var processingHelper = new Processing(import.FileName);
            var slide = processingHelper.Slide;

            Console.WriteLine("Ausschnitt aus Slide extrahieren mit originaler Auflösung...");
            int partImageWidth = import.LowerRight.X - import.UpperLeft.X;
            int partImageHeight = import.LowerRight.Y - import.UpperLeft.Y;
            Bitmap partImage = slide.GetImagePart(
              import.UpperLeft.X, import.UpperLeft.Y,
              partImageWidth, partImageHeight,
              partImageWidth, partImageHeight
            );

            #region global tissue detection
            Console.WriteLine("Gewebe suchen und in separatem Layer speichern...");
            var bitmapProcessor = new BitmapProcessor(partImage);
            ObjectLayer overviewLayer = new TissueDetector().Execute(bitmapProcessor, Radius, NoiseLevel);
            bitmapProcessor.Dispose();

            Console.WriteLine("Gewebe-Layer in Ausschnitt zeichnen + speichern...");
            DrawObjectsToImage(partImage, overviewLayer, Color.Black);
            partImage.Save(processingHelper.DataPath + "ImagePartTissue.png");
            #endregion global tissue detection

            #region Deconvolution
            Console.WriteLine("Execute deconvolution 3...");
            var gpX = new ColorDeconvolution().Get3rdStain(partImage, ColorDeconvolution.KnownStain.HaematoxylinEosin);
            gpX.Dispose();
            Bitmap gpX_bmp = gpX.Bitmap;
            gpX_bmp.Save(processingHelper.DataPath + "ImagePartColor3.png");

            Console.WriteLine("Execute deconvolution 2...");
            var gpE = new ColorDeconvolution().Get2ndStain(partImage, ColorDeconvolution.KnownStain.HaematoxylinEosin);
            gpE.Dispose();
            Bitmap gpE_bmp = gpE.Bitmap;
            gpE_bmp.Save(processingHelper.DataPath + "ImagePartColor2.png");

            Console.WriteLine("Execute deconvolution 1...");
            var gpH = new ColorDeconvolution().Get1stStain(partImage, ColorDeconvolution.KnownStain.HaematoxylinEosin);
            gpH.Dispose();
            Bitmap gpH_bmp = gpH.Bitmap;
            gpH_bmp.Save(processingHelper.DataPath + "ImagePartColor1.png");
            #endregion Deconvolution

            #region execute edge detection
            Console.WriteLine("Execute edge detection...");
            SobelResponse responseH = Filtering.ExecuteSobel(gpH_bmp);
            SobelResponse responseE = Filtering.ExecuteSobel(gpE_bmp);
            var substracted = new double[responseH.Size.Width, responseH.Size.Height];
            var substractedRange = new Range<double>();
            for (var x = 0; x < responseH.Size.Width; x++)
            {
              for (var y = 0; y < responseH.Size.Height; y++)
              {
            var value = Math.Max(0, responseE.Gradient[x, y] - responseH.Gradient[x, y]);
            substracted[x, y] = value;
            substractedRange.Add(value);
              }
            }
            double[,] nonMaximumSupression = Filtering.ExecuteNonMaximumSupression(substracted, responseE.Orientation);
            Bitmap edges = Visualization.Visualize(nonMaximumSupression, Visualization.CreateColorizing(substractedRange.Maximum));
            edges.Save(processingHelper.DataPath + "ImagePartEdges.png");
            #endregion execute edge detection

            exportItems.Add(
              new Ausgabe {
            Identify = import.Identify,
            Result = false,
            Message = "kein Fehler"
              }
            );
              }
        }
        /// <summary>
        /// Updates the actual range displayed on the axis.
        /// </summary>
        private void UpdateActualRange()
        {
            Action action = () =>
            {
                Range<IComparable> dataRange = new Range<IComparable>();
                if (ProtectedMaximum == null || ProtectedMinimum == null)
                {
                    if (Orientation == AxisOrientation.None)
                    {
                        if (ProtectedMinimum != null)
                        {
                            this.ActualRange = OverrideDataRange(new Range<IComparable>(ProtectedMinimum, ProtectedMinimum));
                        }
                        else
                        {
                            this.ActualRange = OverrideDataRange(new Range<IComparable>(ProtectedMaximum, ProtectedMaximum));
                        }
                    }
                    else
                    {
                        IEnumerable<Range<IComparable>> values =
                            this.RegisteredListeners
                                .OfType<IRangeProvider>()
                                .Select(rangeProvider => rangeProvider.GetRange(this));

                        foreach (Range<IComparable> range in values)
                        {
                            dataRange = dataRange.Add(range);
                        }

                        this.ActualRange = OverrideDataRange(dataRange);
                    }
                }
                else
                {
                    this.ActualRange = new Range<IComparable>(ProtectedMinimum, ProtectedMaximum);
                }
            };

            

            action();
        }
Пример #13
0
            /// <summary>
            /// Импортирует фал данных
            /// </summary>
            /// <param name="fname">адрес фала csv</param>
            /// <param name="startLine">номер строки (с нуля) с которой начинаются данные</param>
            /// <param name="separateDate">Если истина, то дата и время в 1 и 2 столбце соответственно</param>
            /// <returns></returns>
            public static Range Import(string fname, int startLine, bool separateDate = false)
            {
                using (StreamReader sr = new StreamReader(fname, Encoding.Default, true))
                {
                    //сохраненеи заголовка
                    List <string> header = new List <string>();
                    for (int i = 0; i < startLine; i++)
                    {
                        header.Add(sr.ReadLine());
                    }


                    //чтение файла
                    Range res = new Range()
                    {
                        separateDate = separateDate, header = header
                    };
                    while (!sr.EndOfStream)
                    {
                        string   line = sr.ReadLine();
                        string[] arr  = line.Split(';');
                        DateTime key;
                        string   data = "";
                        int      startData;

                        //получение даты
                        if (separateDate) //дата и время в разных столбцах
                        {
                            if (arr.Length < 3 || string.IsNullOrWhiteSpace(arr[0]))
                            {
                                continue;
                            }
                            key       = DateTime.Parse(arr[0]) + TimeSpan.Parse(arr[1]);
                            startData = 2;;
                        }
                        else //дата и время в одном столбце
                        {
                            if (arr.Length < 2 || string.IsNullOrWhiteSpace(arr[0]))
                            {
                                continue;
                            }
                            key       = DateTime.Parse(arr[0]);
                            startData = 1;
                        }

                        //сохранение данных
                        for (int i = startData; i < arr.Length; i++)
                        {
                            data += ";" + arr[i];
                        }

                        if (!res.ContainsKey(key))
                        {
                            res.Add(key, new Item()
                            {
                                Date = key, Data = data
                            });
                        }
                    }
                    res.FileName = Path.GetFileNameWithoutExtension(fname);
                    return(res);
                }
            }