public Region(GrayscaleBitmap mask, Rectangle location, Int32 level, Int32 area, Region parent = null, List<Region> children = null, Boolean stable = false) { this.GrayscaleMask = mask; this.Location = location; this.Level = (byte)level; this.Area = area; this.Variation = -1.0; this.Stable = stable; this.Parent = parent; this.Children = children; }
public HumanDetector(Image IR, Image LIDAR) { /* 1. Находим максимально стабильные области экстремума */ /* 2. Масштабируем найденные области в зависимости от расстояния до объектов. * Слишком удаленные объекты отбрасываем. */ //objects = new ComponentTree(this.GrayscaleIR = new GrayscaleBitmap(this.IR = new Bitmap(IR))).Stable; objects = (new Lidar(this.LIDAR = new Bitmap(LIDAR), (new ComponentTree(this.GrayscaleIR = new GrayscaleBitmap(this.IR = new Bitmap(IR)))).Stable)).Resized; /* 3. Фильтруем регионы по значению dispersiveness и отсеиваем пересекающиеся. * Все регионы, с dispersiveness ниже заданного порога, отбрасываются. */ objects = TargetClassificator(); }
public ResultWindow(GrayscaleBitmap sinogram, GrayscaleBitmap result, IterativeSliceReconstructor reconstructor) { this.sinogram = sinogram; this.result = result; this.reconstructor = reconstructor; InitializeComponent(); sinogramImg.Source = PrepareBitmap(sinogram.Bmp); resultImg.Source = PrepareBitmap(result.Bmp); if (reconstructor != null) { moreIterationsBtn.Visibility = Visibility.Visible; moreIterationsCount.Visibility = Visibility.Visible; progressBar.Visibility = Visibility.Visible; moreIterationsColumn.Width = new GridLength(1, GridUnitType.Star); } else { moreIterationsBtn.Visibility = Visibility.Hidden; moreIterationsCount.Visibility = Visibility.Hidden; progressBar.Visibility = Visibility.Hidden; moreIterationsColumn.Width = new GridLength(0); } }
List<Node> stable; /* Максимально стабильные области экстремума */ #endregion Fields #region Constructors public ComponentTree(GrayscaleBitmap original) { pixels = original.DecreasingCountingSort(); accessible = new Int32[original.Width, original.Height]; for (Int32 i = 0; i < original.Width; i++) { for (Int32 j = 0; j < original.Height; j++) { accessible[i, j] = Int32.MinValue; } } QNode = new DisjointSet(Length); QTree = new DisjointSet(Length); nodes = new Node[Length]; lowestNode = new Int32[Length]; stable = new List<Node>(); MSERDetector(); }
private Region CreateRegion(List<Pixel> pattern) { //if (pattern.Count < 0.1 * width * height) //{ // return null; //} int minX = pattern.Min(p => p.Position.X); int maxX = pattern.Max(p => p.Position.X); int minY = pattern.Min(p => p.Position.Y); int maxY = pattern.Max(p => p.Position.Y); int regionWidth = maxX + 1 - minX; int regionHeight = maxY + 1 - minY; var bmp = new GrayscaleBitmap(regionWidth, regionHeight); foreach (Pixel pix in pattern) { bmp[pix.Position.X - minX, pix.Position.Y - minY] = pix.color; } return new Region(bmp, new Rectangle(minX, minY, regionWidth, regionHeight), level, pattern.Count, input); }
static void Main(string[] args) { //if (args.Length >= 1 && args[0].Equals("-s")) //{ // GenerateSinogram(args); // return; //} /*GrayscaleBitmap bmp = new GrayscaleBitmap(1024,1024); * * Console.WriteLine(bmp.Width); * Console.WriteLine(bmp.Height); * * for (int i = 0; i < bmp.Height; i++) * { * for (int j = 0; j < bmp.Width; j++) * { * bmp[i, j] = Math.Sqrt(Math.Pow((double)i, 2.0) + Math.Pow((double)j, 2.0)); * } * } * * bmp.Stretch(); * * bmp.SaveToFile("pokus.bmp");*/ /*GrayscaleBitmap bmp = new GrayscaleBitmap("star.png"); * double angle = 0; * ProjectionHandler projectionHandler = new ProjectionHandlerRaycast(); * double[] projection = projectionHandler.CreateProjection(bmp, angle); * GrayscaleBitmap projectedBmp = projectionHandler.ExtrudeProjection(projection, angle); * projectedBmp.SaveToFile("projected.bmp");*/ String inputFilename = args.Length >= 1 ? args[0] : "Shapes.bmp"; String outputFilename = args.Length >= 2 ? args[1] : "result.bmp"; /*GrayscaleBitmap bmp = new GrayscaleBitmap(500, 500); * double begin = -bmp.Width / 2.0; * double end = bmp.Width / 2.0; * for (int i = 0; i < bmp.Width; i++) * { * for (int j = 0; j < bmp.Height; j++) * { * double x = (i + begin) / (bmp.Width / 2.0); * double y = (j + begin) / (bmp.Width / 2.0); * double value = x * x + y * y; * if (value > 1) * bmp[i, j] = 0; * else * bmp[i, j] = value; * } * } * bmp.SaveToFile("paraboloid.bmp");*/ GrayscaleBitmap bmp = new GrayscaleBitmap(inputFilename); bmp = bmp.CreateSquareBitmap(); Console.WriteLine("Generating projections"); double angle = 1; List <double[]> projections = new ProjectionHandlerRaycast().GenerateProjections(bmp, (int)(180.0 / angle)); //NoiseMaker.AddNoise(projections, 0.5); //GrayscaleBitmap sinogram = SinogramHandler.ProjectionsToSinogram(projections); //EdgeDetectorRoberts.Instance.Apply(sinogram); //GrayscaleBitmap laplaceSinogram = sinogram.Copy(); //for (int i = 0; i < 1; i++) //{ // Filter2D.GetLaplace().Apply(laplaceSinogram); // sinogram += laplaceSinogram; //} //sinogram.SaveToFile("sinogram.bmp"); ////Filter1D.GetHammingFilter3().Apply(projections); ////sinogram = SinogramHandler.ProjectionsToSinogram(projections); //Filter2D.GetGauss55().Apply(sinogram); //////Filter2D.GetGauss55().Apply(sinogram); //////Filter2D.GetGauss55().Apply(sinogram); ////sinogram.SaveToFile("sinogram_after.bmp"); //projections = SinogramHandler.SinogramToProjections(sinogram); //Filter1D.GetLaplaceFilter().Apply(projections); //Filter1D.GetLaplaceFilter().Apply(projections); //Filter1D.GetLaplaceFilter().Apply(projections); //GrayscaleBitmap sinogram = GrayscaleBitmap.Sinogram(projections); //sinogram.Stretch(); //sinogram.SaveToFile("sinogram.bmp"); //List<double[]> projections = SinogramHandler.SinogramToProjections(new GrayscaleBitmap(inputFilename)); //double angle = 180.0 / projections.Count; //List<double[]> projections = new AnalyticParaboloidProjector().GenerateProjections(500, (int)(180.0 / angle)); IterativeSliceReconstructor reconstructor = new IterativeSliceReconstructor(projections, angle, new ProjectionHandlerRaycast(), false); //BackProjectionSliceReconstructor reconstructor = new IterativeSliceReconstructor(projections, angle, new ProjectionHandlerRaycast(), false); Console.WriteLine("Reconstructing"); GrayscaleBitmap result = reconstructor.Reconstruct(540); //GrayscaleBitmap result = reconstructor.Reconstruct(); //GrayscaleBitmap filteredResult = result.Copy(); //ConvolutionFilter2D.GetLaplace().Apply(filteredResult); //result += filteredResult; //result += filteredResult; //result += filteredResult; //result.Stretch(); //result.Stretch(); GrayscaleBitmap error = new GrayscaleBitmap(result.Width, result.Height); for (int i = 0; i < result.Width; i++) { for (int j = 0; j < result.Height; j++) { error[i, j] = Math.Abs(result[i, j] - bmp[i, j]); } } result.SaveToFile(outputFilename); error.SaveToFile(outputFilename + ".error.bmp"); /*ProjectionHandlerBresenham handler = new ProjectionHandlerBresenham(); * handler.generateLine(0.0, 25, 0); * handler.generateLine(0.0, 25, 13); * handler.generateLine(45, 25, 12);*/ }
private void runBtn_Click(object sender, RoutedEventArgs e) { this.IsEnabled = false; int steps = 0; if ((String)reconstructionAlgorithm.SelectedItem == "Back projection") { steps = (int)numberOfProjections.Value; } else { steps = (int)numberOfIterations.Value; } ProgressCounter progressCounter = new ProgressCounterGUI((int)numberOfProjections.Value + steps, progressBar); setState("Loading input image"); GrayscaleBitmap bmp = new GrayscaleBitmap(inputPicture.Text); bmp = bmp.CreateSquareBitmap(); setState("Generating projections"); List <double[]> projections = ((ProjectionHandler)projectionAlgorithm.SelectedItem).GenerateProjections(bmp, (int)numberOfProjections.Value, progressCounter); setState("Filtering projections"); foreach (Filter1D filter in projectionFilterList.Items) { filter.Apply(projections); } GrayscaleBitmap sinogram = SinogramHandler.ProjectionsToSinogram(projections); setState("Filtering sinogram"); foreach (Filter2D filter in sinogramFilterList.Items) { filter.Apply(sinogram); } projections = SinogramHandler.SinogramToProjections(sinogram); GrayscaleBitmap result; IterativeSliceReconstructor passedReconstructor = null; setState("Reconstructing"); if ((String)reconstructionAlgorithm.SelectedItem == "Back projection") { BackProjectionSliceReconstructor reconstructor = new BackProjectionSliceReconstructor(projections, 180.0 / (double)numberOfProjections.Value, (ProjectionHandler)projectionAlgorithm.SelectedItem); result = reconstructor.Reconstruct(progressCounter); } else { IterativeSliceReconstructor reconstructor = new IterativeSliceReconstructor(projections, 180.0 / (double)numberOfProjections.Value, (ProjectionHandler)projectionAlgorithm.SelectedItem, (bool)allowNegativeValuesCheckBox.IsChecked); result = reconstructor.Reconstruct((int)numberOfIterations.Value, progressCounter); passedReconstructor = reconstructor; } setState("Nothing to do"); progressCounter.Reset(); ResultWindow resultWnd = new ResultWindow(sinogram, result, passedReconstructor); resultWnd.Show(); this.IsEnabled = true; }