Esempio n. 1
0
        private void goBtn_Click(object sender, EventArgs e)
        {
            x = 1024;
            y = 1024;
            openSource.Text = openKernel.Text = "Open";
            data            = Reader.readFile(image, x, y, false);
            //Copy data line for Fourier
            //data = Reader.Rotate(data);
            tempFourier1 = PrepareVerticalFouirier(data, line);
            //Print Fourier
            Fourier.Draw(fourierChart, tempFourier1, SeriesChartType.Spline);
            if (kernel != "empty")
            {
                kernelData = Reader.readHex(kernel);
            }
            double[][] result = data;
            pictureBefore.Image = Reader.Draw(Reader.RescaleImage(data, x, y), x, y);
            switch (listOperations.SelectedItem.ToString().Trim())
            {
            case ("Knearest"):
            {
                result = Zoom.Knearest(data, 2);
            }
            break;

            case ("Bilinear"):
            {
                result = Zoom.Bilinear(data, 2);
            }
            break;

            case ("Logarithm"):
            {
                result = Zoom.Logarithm(data, 2);
            }
            break;

            case ("Negative"):
            {
                result = Processing.Nagative(data, 256);
            }
            break;

            case ("Gamma"):
            {
                //improve C after 1 for darkness, degrade after 1 for light
                //For xcr (need rescale + normilize)
                result = Processing.Gamma(data, 1, 0.7);
            }
            break;

            case ("Remove Border (LPF)"):
            {
                result = Border.StepFunction(result, 180, 180, 8);
                result = Border.RemoveBorder_LPF(result, 0.05, 16, dt);
            }
            break;

            case ("Remove Border (Gradient)"):
            {
                result = Border.Gradient(result);
                result = Border.StepFunction(result, 1, 1, 8);
            }
            break;

            case ("Remove Border (Laplassian)"):
            {
                result = Border.Laplassian(result);
            }
            break;

            case ("Recover"):
            {
                if (kernel != "empty")
                {
                    result = Recover.recovery(result, kernel);
                }
                else
                {
                    MessageBox.Show("no kernel uploaded");
                }
            }
            break;

            case ("Recover with Noize"):
            {
                if (kernel != "empty")
                {
                    result = Recover.recoveryWithNoize(result, kernel, 0.01);
                }
                else
                {
                    MessageBox.Show("no kernel uploaded");
                }
            }
            break;

            case ("Remove Grid"):
            {
                //Calculate grid fcuts:
                //среднее по массиву Фурье:
                double avg = Fourier.CalcAVG(tempFourier1);
                //среднеквадратичное отклонение (сигма)
                double sigma = Fourier.CalcStandardDeviation(tempFourier1);
                //поиск пика:
                double[] temp = new double[tempFourier1.Length];
                for (int i = 0; i < tempFourier1.Length / 2; i++)
                {
                    if (tempFourier1[i] > avg + sigma / 4)
                    {
                        temp[i] = i * (dt / data.Length);
                    }
                }
                var peaks = from point in temp
                            where point != 0
                            select point;
                double lefttmp = 0.275609756097561;
                double left    = peaks.Min();
                double right   = peaks.Max();
                result = Recover.removeLines(data, lefttmp, right, 64, dt);
            }
            break;

            case ("Dilatation"):
            {
                result = Border.StepFunction(result, 180, 180, 8);
                double[][] step = result;
                step   = Copy2D(result, step);
                result = Processing.ApplyMaskDilatation(result, 10, 128);
                for (int i = 0; i < step.Length; i++)
                {
                    for (int j = 0; j < step[0].Length; j++)
                    {
                        result[i][j] -= step[i][j];
                    }
                }
            }
            break;

            case ("Erosion"):
            {
                result = Border.StepFunction(result, 180, 180, 8);
                double[][] step = result;
                step = Copy2D(result, step);
                step = Processing.ApplyMaskErosion(step, 10, 128);
                for (int i = 0; i < step.Length; i++)
                {
                    for (int j = 0; j < step[0].Length; j++)
                    {
                        result[i][j] -= step[i][j];
                    }
                }
            }
            break;

            default:
                break;
            }
            if (listOperations.SelectedItem.ToString().Trim() != "Equalize")
            {
                pictureAfter.Image = Reader.Draw(Reader.RescaleImage(result, x, y), x, y);
            }
            else
            {
                //Prepare Hist
                int levels = 256;
                DrawHist(Parser.BitmapTo2D((Bitmap)pictureBefore.Image), chartHisto, levels);
                //LEGACY
                //Draw Picture
                pictureBefore.Image = Parser.readFile(image);
                Bitmap temp = (Bitmap)pictureBefore.Image.Clone();
                pictureAfter.Image = Processing.Equalizing(temp);
            }
        }