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();
                }
            }
        }
        private async void analyzeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (isBinarized)
            {
                progressBar = new GeneratorProgressBar
                {
                    Info = "Looking for shapes",
                };


                DisableMenu();
                DisablePictureBox();

                progressBar.Show();

                List <PoreAnalyzeData> newData;

                newData = await Task.Run(() => _processor.FindShapes(_image.ViewImage));

                progressBar.Info = "Analyzing shapes";

                var analyzedShapes = await AnalyzeShapesAsync(newData);

                if (_poresDatabase == null)
                {
                    _poresDatabase = analyzedShapes;
                }
                else
                {
                    _poresDatabase.AddRange(analyzedShapes);
                    _poresDatabase = _poresDatabase.GroupBy(pd => pd.Id).Select(g => g.First()).ToList();
                }
                progressBar.Dispose();

                EnableMenu();
                EnablePictureBox();
            }
            else
            {
                if (BinarizeFirstDialog() == DialogResult.Yes)
                {
                    binarizationToolStripMenuItem_Click(sender, e);
                    analyzeToolStripMenuItem_Click(sender, e);
                }
            }
        }