public Form1(IImageProcessor imageProcessor) { InitializeComponent(); _processor = imageProcessor; _image = new Model.Image(); _image.OnViewImageChange += _image_OnViewImageChange; // pictureBox1.MouseClick += PictureBox1_MouseClick; globalSettings = new GlobalSettings(); _shapeAnalyzer = new ShapeAnalyzer(globalSettings.SimilarityCoefficient); _processor.OnStart += (s, blobsNumber) => { progressBar.setMaxValue(blobsNumber * 2); }; _processor.OnProgress += (s, ea) => { progressBar.Increment(1); }; pictureBox1.MouseMove += (s, a) => { if (pictureBox1.Image != null) { try { cordsLabel.Text = $"({a.X},{a.Y})"; grayLabel.Text = $"Gray: {_image.ViewImage.GetPixel(a.X, a.Y).R}"; } catch (IndexOutOfRangeException ex) { } } }; pictureBox1.MouseLeave += (s, a) => { cordsLabel.Text = string.Empty; grayLabel.Text = string.Empty; }; this.SizeChanged += Form1_ResizeEnd; _shapeAnalyzer.ShapeCountChange += (s, count) => { setShapeCountLabel(count); }; }
private async void generateMicrostructureToolStripMenuItem_Click(object sender, EventArgs e) { if (_shapeAnalyzer.ShapeDictionary.Count == 0) { string msg = "Import shape database or analyze image first!"; string caption = "Shape database is empty"; MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { GeneratorDataInputBox form = new GeneratorDataInputBox(); if (form.ShowDialog() == DialogResult.OK) { progressBar = new GeneratorProgressBar { Info = "Generating microstructure" }; progressBar.setMaxValue(100); DisableMenu(); DisablePictureBox(); progressBar.Show(); //int physicalWidth = Convert.ToInt32(form.MicrostructureWidth * form.Ratio); //int physicalHeight = Convert.ToInt32(form.MicrostructureHeight * form.Ratio); MicrostructureGenerator generator = new MicrostructureGenerator(form.MicrostructureWidth, form.MicrostructureHeight, 1 / form.Ratio, _processor); generator.OnProgress += (s, percentage) => { progressBar.Increment(percentage * 100 / form.Volume); }; var bmp = await Task.Run(() => generator.GenerateMicrostructure(_poresDatabase, form.Volume)); progressBar.Dispose(); EnableMenu(); EnablePictureBox(); int pixelWidth = Convert.ToInt32(form.MicrostructureWidth * 1 / form.Ratio); int pixelHeight = Convert.ToInt32(form.MicrostructureHeight * 1 / form.Ratio); bmp = _processor.Rescale(bmp, pixelWidth, pixelHeight); var bm2 = _processor.ConvertToGrayscale(bmp); _image.ViewImage = _processor.Binarization(bm2, 127); RescalePictureBox(); } } }