private void OutputSegmentations(Workbook wb, string filename, int width, int height)
        {
            Worksheet ws = wb.Worksheets[0];

            //image reading
            Bitmap b = new Bitmap(filename);

            double[,,] arrayImage = BitmapConverter.BitmapToDoubleRgb(b);

            //MemoryStream memoryStream = new MemoryStream();
            //b.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            //processing cycle
            int counter = 0;

            for (int k = kMin, i = 0; k <= kMax; k += kStep, i++)
            {
                int currentRow = i * (RowsForDetails + 1) + startImageRowNumber;

                for (int min = minMin, j = startImageColumnNumber; min <= minMax; min += minStep, j++)
                {
                    //получение результатов сегментации
                    Segmentation segmentationObj = new Segmentation();
                    Bitmap       res             = segmentationObj.DoSegmentation(b, 0.84, k, min, new SegmentationBasedOnGraph.ColorShemes.RGBColorSheme());

                    //приведение результатов к нужному размеру
                    res = Service.ResizeImage(res, width, height);

                    ///сохранения результата в поток
                    MemoryStream memoryStream = new MemoryStream();
                    res.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //добавления сегментации на страницу
                    ws.Cells[currentRow + 1, j].Value = segmentationObj.m_componentLength.ToString();

                    int idx = ws.Pictures.Add(currentRow, j, memoryStream);

                    ws.Cells[currentRow + 1, j].Value = $"Сегментів: {segmentationObj.m_componentLength}";
                    ws.Cells[currentRow + 2, j].Value = $"Сума внутрішньокластерних дисперсій: {segmentationObj.GetInternalDifferenceAssessment().ToString("0.00")}";

                    counter++;
                    System.Diagnostics.Debug.WriteLine($"Сегментация {counter} посчитана");
                }
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = String.Empty;

            double sigma = Convert.ToDouble(sigmaTextBox.Text.Replace(".", ","));
            int    k     = Convert.ToInt32(KtextBox.Text);
            int    min   = Convert.ToInt32(MinTextBox.Text);

            IColorSheme colorSheme = null;

            if (GreyScaleRadioButton.Checked)
            {
                colorSheme = new GrayScaleColorSheme();
            }
            if (RgbRadioButton.Checked)
            {
                colorSheme = new RGBColorSheme();
            }
            if (LabRadioButton.Checked)
            {
                colorSheme = new LabColorSheme();
            }

            Segmentation segmentObj = new Segmentation();

            segmented = segmentObj.DoSegmentation(m_workImage, sigma, k, min, colorSheme);
            OutputBitmapOnPictureBox(segmented);
            outoutSegmented = true;

            //вывод в текстбокс
            textBox1.Text += $"Сегментів: {segmentObj.m_componentLength}" + Environment.NewLine + Environment.NewLine;

            if (AssessmentCheckBox.Checked)
            {
                textBox1.Text += segmentObj.CalcAssessments();
            }
        }