コード例 #1
0
        static ColorFloatImage ReadImage(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new Exception("File doesn't exist");
            }

            return(ImageIO.FileToColorFloatImage(filename));
        }
コード例 #2
0
        public void SaveImage(ColorFloatImage image, string filename)
        {
            List <string> outputFileName = new List <string>()
            {
                $"{inputname}_", "", ".bmp"
            };

            outputFileName[1] = filename;
            ImageIO.ImageToFile(image, String.Concat(outputFileName));
        }
コード例 #3
0
        public ColorFloatImage ReadImage()
        {
            string inputFileName = $"input//{inputname}.bmp";

            if (!File.Exists(inputFileName))
            {
                Console.WriteLine("File doesn't exist");
                return(null);
            }
            return(ImageIO.FileToColorFloatImage(inputFileName));
        }
コード例 #4
0
        static void Main(string[] args)
        {
            ColorFloatImage output_image = null;

            if (args[0] == "mirror")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[2]);
                output_image = mirror(image, args[1]);
                ImageIO.ImageToFile(output_image, args[3]);
            }
            else if (args[0] == "rotate")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[3]);
                output_image = rotate(image, args[1], Convert.ToInt32(args[2]));
                ImageIO.ImageToFile(output_image, args[4]);
            }
            else if (args[0] == "sobel")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[3]);
                output_image = sobel(image, args[1], args[2]);
                ImageIO.ImageToFile(output_image, args[4]);
            }
            else if (args[0] == "median")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[2]);
                output_image = median(image, Convert.ToInt32(args[1]));
                ImageIO.ImageToFile(output_image, args[3]);
            }
            else if (args[0] == "gauss")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[3]);
                output_image = gauss(image, args[1], (float)(Convert.ToDouble(args[2])));
                ImageIO.ImageToFile(output_image, args[4]);
            }
            else if (args[0] == "gradient")
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(args[3]);
                output_image = gradient(image, args[1], (float)(Convert.ToDouble(args[2])));
                //output_image = img_expansion(image, "odd", 40);
                ImageIO.ImageToFile(output_image, args[4]);
            }
            Console.WriteLine("Image trasformed successfully");
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: dormouses/fur
        static void Main()
        {
            PointPairList       us = new PointPairList(), sift = new PointPairList();
            GrayscaleFloatImage img = ImageIO.FileToGrayscaleFloatImage("lena_min.bmp");
            var a = Count.lpc("lena", img, 2, 0, 0, 0, true);

            /*
             * Console.WriteLine("начало");
             * //   Count.CountMetric("lena_min");
             * //   Count.CountMetric("lena_min_rot");
             * int corresp = Compare.CountCorrespondenses("lena_min", "lena_min_rot");
             *
             * for (float th = 0.0f; th < 10; th += 0.1f)
             *  Compare.Compare_metrik("lena_min", "lena_min_rot", 0, corresp, th, us, 1);
             *
             * for (float th = 0; th < 1000; th += 100)
             *  Compare.Compare_metrik("lena_min", "lena_min_rot", 1, corresp, th, sift);
             *
             * Extra.DrawGpaph(us, sift, "ans_quant.bmp");*/
        }
コード例 #6
0
        static void Main(string[] args)
        {
            //var readLine = Console.ReadLine();
            //if (readLine == null) return;
            //var args = readLine.Split(' ');
            //var args = new[] { "house2.bmp", "house222.bmp", "canny", "1", "0,25", "0,1" };

            //task1
            //Инверсия значений пикселей изображения
            if (args.Length == 3 && args[2] == "invert")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                Inversion.InversionProcess(image);
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Отражение изображения по вертикали и по горизонтали
            if (args.Length == 4 && args[2] == "mirror")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                if (args[3] == "x")
                {
                    Reflection.FlipHorizontal(image);
                }
                if (args[3] == "y")
                {
                    Reflection.FlipVertical(image);
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Поворот изображений по и против часовой стрелки на 90, 180 и 270 градусов(на произвольный угол)
            if (args.Length == 5 && args[2] == "rotate")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                if (args[3] == "cw")
                {
                    image = Rotate.ClockWiseRotate(image, angle: int.Parse(args[4]));
                }
                if (args[3] == "ccw")
                {
                    image = Rotate.CounterClockWiseRotate(image, angle: int.Parse(args[4]));
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //фильтр Превитта
            if (args.Length == 4 && args[2] == "prewitt")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                if (args[3] == "x")
                {
                    image = MedianFiltering.Convolution(image, Filters.PrewittHorizontal(), 3, 2);
                }
                if (args[3] == "y")
                {
                    image = MedianFiltering.Convolution(image, Filters.PrewittVertical(), 3, 2);
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //фильтр Собеля
            if (args.Length == 4 && args[2] == "sobel")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                if (args[3] == "x")
                {
                    image = MedianFiltering.Convolution(image, Filters.SobelHorizontal(), 3);
                }
                if (args[3] == "y")
                {
                    image = MedianFiltering.Convolution(image, Filters.SobelVertical(), 3);
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //фильтр Робертса
            if (args.Length == 4 && args[2] == "roberts")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                if (args[3] == "1")
                {
                    image = MedianFiltering.Convolution(image, Filters.RobertsMainDiagonal(), 2, 2);
                }
                if (args[3] == "2")
                {
                    image = MedianFiltering.Convolution(image, Filters.RobertsAdditionalDiagonal(), 2, 2);
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Медианная фильтрация с квадратным окном произвольного размера
            if (args.Length == 4 && args[2] == "median")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                image = MedianFiltering.MedianFilter(image, kernelSize: int.Parse(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Свёртка с фильтром Гаусса с произвольным выбором параметра — радиуса σ
            if (args.Length == 4 && args[2] == "gauss")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image    = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                var data     = new double[image.rawdata.Length];
                var template = new double[image.rawdata.Length];
                for (var i = 0; i < image.rawdata.Length; i++)
                {
                    data[i] = Convert.ToDouble(image.rawdata[i]);
                }
                ConvolutionGauss.GaussProcess(data, image.Width, image.Height, sigma: double.Parse(args[3]), windowSize: 9, temp: template, dest: data);
                for (var i = 0; i < image.rawdata.Length; i++)
                {
                    image.rawdata[i] = Convert.ToSingle(data[i]);
                }
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Вычисление модуля градиента как корень из суммы квадратов свёрток с первой производной фильтра Гаусса по горизонтали и вертикали
            if (args.Length == 4 && args[2] == "gradient")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                ConvolutionGauss.GradientProcess(image.rawdata, image.Width, image.Height, double.Parse(args[3]), (int)(double.Parse(args[3]) * 6), image.rawdata);
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Фильтр Габора с произвольными параметрами
            if (args.Length == 8 && args[2] == "gabor")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                image = ConvolutionGauss.Gabor(image, Filters.Gabor((int)(6 * double.Parse(args[3])), double.Parse(args[3]), double.Parse(args[6]), double.Parse(args[5]), double.Parse(args[4]), double.Parse(args[6])), (int)(6 * double.Parse(args[3])), (int)(6 * double.Parse(args[3])), int.Parse(args[7]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Обнаружение сосудов на изображениях глазного дна с помощью фильтров Габора
            if (args.Length == 4 && args[2] == "vessels")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                image = ConvolutionGauss.Vessels(image, (int)(6 * Convert.ToDouble(args[3])), Convert.ToDouble(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //task2
            //Увеличение изображений в вещественное число раз с помощью билинейной интерполяции
            if (args.Length == 4 && args[2] == "up_bilinear")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                image = ImageResolution.Bilinear(image, Convert.ToDouble(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Увеличение изображений в вещественное число раз с помощью бикубической интерполяции
            if (args.Length == 4 && args[2] == "up_bicubic")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                var resultImage = ImageResolution.Bicubic(image, Convert.ToDouble(args[3]));
                ImageIO.ImageToFile(resultImage, outputFileName);
            }
            //Понижение разрешения изображений в вещественное число раз
            if (args.Length == 4 && args[2] == "downsample")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                image = ImageResolution.DownBilinear(image, Convert.ToDouble(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Вычисление метрик сравнения изображений(MSE и PSNR, SSIM и MSSIM)
            if (args.Length == 4 && args[2] == "metric")
            {
                string inputFileName = args[0], inputFileName2 = args[1];
                if (!File.Exists(inputFileName) || !File.Exists(inputFileName2))
                {
                    return;
                }
                var    image  = ImageIO.FileToGrayscaleFloatImage(inputFileName);
                var    image2 = ImageIO.FileToGrayscaleFloatImage(inputFileName2);
                double result;
                switch (args[3])
                {
                case "mse":
                    result = Metrics.Mse(image, image2);
                    Console.WriteLine(result);
                    Console.ReadKey();
                    break;

                case "psnr":
                    result = Metrics.Psnr(image, image2);
                    Console.WriteLine(result);
                    Console.ReadKey();
                    break;

                case "ssim":
                    result = Metrics.Ssim(image.rawdata, image2.rawdata, image.Width, image.Height);
                    Console.WriteLine(result);
                    Console.ReadKey();
                    break;

                case "mssim":
                    result = Metrics.Mssim(image.rawdata, image2.rawdata, image.Width, image.Height);
                    Console.WriteLine(result);
                    Console.ReadKey();
                    break;
                }
            }
            //task3
            //Алгоритм детектирования границ Канни
            if (args.Length == 6 && args[2] == "canny")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                var image2 = Canny.Process(image, Convert.ToSingle(args[3]), Convert.ToSingle(args[4]), Convert.ToSingle(args[5]));
                ImageIO.ImageToFile(image2, outputFileName);
            }
            //Алгоритм Харриса для детектирования углов
            if (args.Length == 4 && args[2] == "harris")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                image = Harris.Process(image, double.Parse(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
            //Билатеральная фильтрация изображений
            if (args.Length == 5 && args[2] == "bilateral")
            {
                string inputFileName = args[0], outputFileName = args[1];
                if (!File.Exists(inputFileName))
                {
                    return;
                }
                var image = ImageIO.FileToGrayscaleFloatImage(inputFileName);

                image = Bilateral.Process(image, double.Parse(args[3]), double.Parse(args[3]));
                ImageIO.ImageToFile(image, outputFileName);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: tamerlansb/ImageProcessing
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                return;
            }
            string InputFileName = args[args.Length - 2], OutputFileName = args[args.Length - 1];

            if (!File.Exists(InputFileName))
            {
                return;
            }

            switch (args[0])
            {
            case ("prewitt"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[1] == "y")
                    {
                        ImageProcessing.Prewitt(image, "y");
                    }
                    if (args[1] == "x")
                    {
                        ImageProcessing.Prewitt(image, "x");
                    }
                }
                else
                {
                    ImageProcessing.Prewitt(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("invert"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.InvertImage(image);
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("sobel"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[1] == "y")
                    {
                        ImageProcessing.Sobel(image, "y");
                    }
                    if (args[1] == "x")
                    {
                        ImageProcessing.Sobel(image, "x");
                    }
                }
                else
                {
                    ImageProcessing.Sobel(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("mirror"):
            {
                if (args.Length >= 4)
                {
                    ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                    if (args[1] == "y")
                    {
                        ImageProcessing.FlipImageY(image);
                    }
                    if (args[1] == "x")
                    {
                        ImageProcessing.FlipImageX(image);
                    }
                    ImageIO.ImageToFile(image, OutputFileName);
                }
                break;
            }

            case ("roberts"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[1] == "1")
                    {
                        ImageProcessing.Roberts(image, 1);
                    }
                    if (args[1] == "2")
                    {
                        ImageProcessing.Roberts(image, 2);
                    }
                }
                else
                {
                    ImageProcessing.Roberts(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("rotate"):
            {
                if (args.Length < 5)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.Rotate(ref image, args[1], float.Parse(args[2], CultureInfo.InvariantCulture));
                ImageIO.ImageToFile(image, OutputFileName);
            }
            break;

            case ("gauss"): {
                if (args.Length < 4)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length < 5)
                {
                    image = ImageProcessing.Gauss(image, float.Parse(args[1], CultureInfo.InvariantCulture));
                }
                else
                {
                    image = ImageProcessing.Gauss(image, float.Parse(args[1], CultureInfo.InvariantCulture), float.Parse(args[2], CultureInfo.InvariantCulture));
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("median"):
            {
                if (args.Length < 4)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.Median(image, Int32.Parse(args[1]));
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("gabor"):
            {
                GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName);
                image = ImageProcessing.Gabor(image, Single.Parse(args[1], CultureInfo.InvariantCulture), Single.Parse(args[2], CultureInfo.InvariantCulture), Single.Parse(args[3], CultureInfo.InvariantCulture), Single.Parse(args[4], CultureInfo.InvariantCulture), Single.Parse(args[5], CultureInfo.InvariantCulture));
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("gradient"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.gradient(ref image, Single.Parse(args[1], CultureInfo.InvariantCulture));
                ImageIO.ImageToFile(ImageIO.BitmapToGrayscaleFloatImage(ImageIO.ImageToBitmap(image)), OutputFileName);
                break;
            }

            case ("vessels"):
            {
                ColorFloatImage image  = ImageIO.FileToColorFloatImage(InputFileName);
                var             result = ImageProcessing.vessels(image, Single.Parse(args[3], CultureInfo.InvariantCulture));
                ImageIO.ImageToFile(result, OutputFileName);
                break;
            }

            case ("canny"):
            {
                ColorFloatImage image  = ImageIO.FileToColorFloatImage(InputFileName);
                var             result = EdgeDetection.Canny(image, Single.Parse(args[1], CultureInfo.InvariantCulture), Single.Parse(args[2], CultureInfo.InvariantCulture), Single.Parse(args[3], CultureInfo.InvariantCulture));
                ImageIO.ImageToFile(result, OutputFileName);
                break;
            }

            case ("mse"):
            {
                ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]),
                                image2 = ImageIO.FileToColorFloatImage(args[2]);
                Console.WriteLine(ImageInterpolation.MSE(image1, image2));
                break;
            }

            case ("psnr"):
            {
                ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]),
                                image2 = ImageIO.FileToColorFloatImage(args[2]);
                Console.WriteLine(ImageInterpolation.PSNR(image1, image2));
                break;
            }

            case ("ssim"):
            {
                ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]),
                                image2 = ImageIO.FileToColorFloatImage(args[2]);
                Console.WriteLine(ImageInterpolation.SSIM(image1, image2));
                break;
            }

            case ("mssim"):
            {
                ColorFloatImage image1 = ImageIO.FileToColorFloatImage(args[1]),
                                image2 = ImageIO.FileToColorFloatImage(args[2]);
                Console.WriteLine(ImageInterpolation.MSSIM(image1, image2));
                break;
            }

            case ("unsharp"):
            {
                ColorFloatImage image  = ImageIO.FileToColorFloatImage(InputFileName);
                var             result = ImageProcessing.unsharp(image);
                ImageIO.ImageToFile(result, OutputFileName);
                break;
            }

            default: break;
            }
            //GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName);
            //FlipImage(image);
        }
コード例 #8
0
        public static float[,] lpc(string name, GrayscaleFloatImage image, float sigma, float th, int x, int y, bool test = false)//новая метрика
        {
            GrayscaleFloatImage image2 = new GrayscaleFloatImage(image.Width, image.Height);

            float sig = sigma, lam = sig;
            float eps = 0.01f;
            int   r   = (int)(3 * sig);

            Complex[][,] img = new Complex[20][, ];
            int l = 0;

            float[,] num   = new float[image.Width, image.Height];
            float[,] ans   = new float[image.Width, image.Height];
            float[,] denum = new float[image.Width, image.Height];
            int[,] mask    = make_mask(x, y, sigma, th, image.Width, image.Height, test);

            //for (sig = 1; sig <=16; sig++)
            //  for (r=3; r<=10; r++)
            //for (lam = 1; lam < 5; lam++)

            {
                for (int q = 0; q < 6; q++)
                {
                    l = 0;
                    int m_l = 5;

                    for (float s = 1; s <= 3; s += 0.5f, l++)
                    {
                        img[l] = Gabor.GaborFiltered(image, mask, (int)(r * s), lam, (float)(q * (Math.PI / 6) + th), sig, 1f, 0f, s);
                    }

                    for (int i = 0; i < image.Width; i++)
                    {
                        for (int j = 0; j < image.Height; j++)
                        {
                            float e_x = 0, e_y = 0, a = 0;
                            for (l = 0; l < m_l; l++)
                            {
                                e_x += (float)img[l][i, j].Re;
                                e_y += (float)img[l][i, j].Im;
                                a   += (float)img[l][i, j].Magnitude;
                            }
                            num[i, j]   += (float)Math.Sqrt(e_x * e_x + e_y * e_y);
                            denum[i, j] += a;
                        }
                    }
                }
                for (int i = 0; i < image.Width; i++)
                {
                    for (int j = 0; j < image.Height; j++)
                    {
                        ans[i, j] = num[i, j] / (eps + denum[i, j]);
                    }
                }

                //    Console.WriteLine("pc {0}",ans[x, y]);
                for (int i = 0; i < image.Width; i++)
                {
                    for (int j = 0; j < image.Height; j++)
                    {
                        image2[i, j] = (float)ans[i, j];
                        image2[i, j] = (float)Math.Round(image2[i, j], 1, MidpointRounding.AwayFromZero);
                    }
                }

                Extra.Norm(image2);
                string pic1 = String.Format("!!ans {0} sigma= {1} lam = {2} rad= {3}", name, sig, lam, r);
                ImageIO.ImageToFile(image2, pic1 + ".bmp");
            }
            return(ans);
        }
コード例 #9
0
        public static void CountMetric(string name)
        {
            StreamReader     sr       = new StreamReader(name + ".key");
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";

            GrayscaleFloatImage img = ImageIO.FileToGrayscaleFloatImage(name + ".bmp");

            float[,] lpc_map;
            StreamWriter file  = new StreamWriter("ans_lpc_all_info" + name + ".txt");
            StreamWriter file1 = new StreamWriter("ans_lpc" + name + ".txt");
            StreamWriter file2 = new StreamWriter("ans_lbp" + name + ".txt");
            int          dots  = 0;

            while (!sr.EndOfStream)
            {
                dots++;
                Console.WriteLine(dots);
                string   str     = sr.ReadLine();
                string[] numbers = str.Split(' ');
                float    x       = (float)Convert.ToDouble(numbers[0], provider);
                float    y       = (float)Convert.ToDouble(numbers[1], provider);
                float    sigma   = (float)Convert.ToDouble(numbers[2], provider);
                float    th      = (float)Convert.ToDouble(numbers[3], provider);
                // if (!(x== && y==250)) continue;
                // if (sigma > 4.5) continue;
                lpc_map = lpc(name, img, sigma, th, (int)Math.Round(x), (int)Math.Round(y));
                file.WriteLine(String.Format("{0} {1} {2} {3} {4}\n", x, y, sigma, th, lpc_map[(int)Math.Round(x), (int)Math.Round(y)]));
                file.Flush();
                file1.WriteLine(String.Format("{0} {1} {2}\n", x, y, lpc_map[(int)Math.Round(x), (int)Math.Round(y)]));
                file1.Flush();
                file2.WriteLine(String.Format("{0} {1} {2} {3}", x, y, sigma, th));
                for (int i = 0; i < 8; i++)
                {
                    try
                    {
                        float alpha = (float)(th + i * Math.PI / 4);
                        file2.WriteLine(String.Format("{0}", lpc_map[(int)((int)Math.Round(x) + sigma * Math.Cos(alpha)), (int)((int)Math.Round(y) + sigma * Math.Sin(alpha))]));
                    }
                    catch
                    {
                        file2.WriteLine("0");
                    }
                }

                for (int i = 0; i < 16; i++)
                {
                    try
                    {
                        float alpha = (float)(th + i * Math.PI / 8);
                        file2.WriteLine(String.Format("{0}", lpc_map[(int)((int)Math.Round(x) + 2 * sigma * Math.Cos(alpha)), (int)((int)Math.Round(y) + 2 * sigma * Math.Sin(alpha))]));
                    }
                    catch
                    {
                        file2.WriteLine("0");
                    }
                }

                file2.WriteLine("\n");
                file2.Flush();
            }
            file.Close();
            file1.Close();
            file2.Close();
            sr.Close();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            //string path = Directory.GetCurrentDirectory();

            if (args.Length < 2)
            {
                Console.WriteLine("Empty arguments");
                return;
            }

            //string inputFileName = String.Concat( new List<string>() { "input//", args[ 0 ], ".bmp" } );
            string        outputFileName = String.Empty;
            List <string> outputName     = new List <string>()
            {
                "", "", "", "", ".bmp"
            };

            ColorFloatImage inputImage;

            #region lab1

            if (_lab1.Contains(args[1]))
            {
                ColorFloatImage outputImage = null;

                switch (args[1])
                {
                case "mirror":

                    outputName[1] = "mirror";
                    inputImage    = ReadImage(args[3]);

                    switch (args[2])
                    {
                    case "x":
                        outputName[2] = "_x";
                        outputImage   = MirrorX(inputImage);
                        break;

                    case "y":
                        outputName[2] = "_y";
                        outputImage   = MirrorY(inputImage);
                        break;
                    }
                    break;

                case "rotate":

                    outputName[1] = "rotate";
                    int angle = (int)GetNumericArg(args[3]);
                    inputImage = ReadImage(args[4]);

                    switch (args[2])
                    {
                    case "cw":
                        outputName[3] = "_cw";
                        outputImage   = RotateCW(inputImage, angle);
                        break;

                    case "ccw":
                        outputName[3] = "_ccw";
                        outputImage   = RotateCW(inputImage, 360 - angle);
                        break;
                    }
                    break;

                case "sobel":
                    outputName[1] = "sobel";
                    outputName[2] = $"_{args[2]}";
                    inputImage    = ReadImage(args[3]);
                    outputImage   = Sobel(inputImage, args[2]);
                    break;

                case "median":
                    outputName[1] = "median";
                    inputImage    = ReadImage(args[3]);
                    int rad = (int)GetNumericArg(args[2]);
                    outputImage = Median(inputImage, rad);
                    break;

                case "gauss":
                    outputName[1] = "gauss";
                    float sigma = GetNumericArg(args[2]);
                    inputImage  = ReadImage(args[3]);
                    outputImage = Gauss(inputImage, sigma);
                    break;

                case "gradient":
                    outputName[1] = "gradient";
                    sigma         = GetNumericArg(args[2]);
                    inputImage    = ReadImage(args[3]);
                    GrayscaleFloatImage newOutputImage = GaussMagnitude(inputImage, sigma);
                    outputFileName = String.Concat(outputName);
                    ImageIO.ImageToFile(newOutputImage, outputFileName);
                    break;

                case "bilateral":
                    outputName[1] = "bilateral";
                    float sigma_d = GetNumericArg(args[2]);
                    float sigma_r = GetNumericArg(args[3]);
                    inputImage  = ReadImage(args[4]);
                    outputImage = Bilateral(inputImage, sigma_d, sigma_r);
                    break;
                }

                if (outputImage != null)
                {
                    outputFileName = String.Concat(outputName);
                    ImageIO.ImageToFile(outputImage, outputFileName);
                }
                return;
            }

            #endregion

            #region lab2

            if (_lab2.Contains(args[1]))
            {
                GrayscaleFloatImage outputImage = null;

                switch (args[1])
                {
                case "mse":
                    CompareImages(args[2], args[3], MSE);
                    break;

                case "psnr":
                    CompareImages(args[2], args[3], PSNR);
                    break;

                case "ssim":
                    CompareImages(args[2], args[3], SSIM);
                    break;

                case "mssim":
                    CompareImages(args[2], args[3], MSSIM);
                    break;

                case "canny":
                    outputName[1] = "canny";
                    float sigma   = GetNumericArg(args[2]);
                    float thrHigh = GetNumericArg(args[3]);
                    float thrLow  = GetNumericArg(args[4]);
                    inputImage  = ReadImage(args[5]);
                    outputImage = Canny(inputImage, sigma, thrHigh, thrLow);
                    break;

                case "gabor":
                    outputName[1] = "gabor";
                    sigma         = GetNumericArg(args[2]);
                    float gamma  = GetNumericArg(args[3]);
                    float theta  = GetNumericArg(args[4]);
                    float lambda = GetNumericArg(args[5]);
                    float psi    = GetNumericArg(args[6]);
                    inputImage  = ReadImage(args[7]);
                    outputImage = Gabor(inputImage, sigma, gamma, theta, lambda, psi);
                    break;

                case "vessels":
                    outputName[1] = "vessels";
                    sigma         = GetNumericArg(args[2]);
                    inputImage    = ReadImage(args[3]);
                    outputImage   = Vessels(inputImage, sigma);
                    break;
                }

                if (outputImage != null)
                {
                    outputFileName = String.Concat(outputName);
                    ImageIO.ImageToFile(outputImage, outputFileName);
                }
                return;
            }
            #endregion
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: tamerlansb/ImageProcessing
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                return;
            }
            string InputFileName = args[0], OutputFileName = args[1];

            if (!File.Exists(InputFileName))
            {
                return;
            }

            switch (args[2])
            {
            case ("harris"):
            {
                GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName);
                GrayscaleFloatImage Res   = EdgeDetection.harris(image, float.Parse(args[3]));
                ImageIO.ImageToFile(Res, OutputFileName);
                break;
            }

            case ("canny"):
            {
                ColorFloatImage     image  = ImageIO.FileToColorFloatImage(InputFileName);
                GrayscaleFloatImage Reslut = EdgeDetection.Canny(image, float.Parse(args[3]), float.Parse(args[4]), float.Parse(args[5]));
                ImageIO.ImageToFile(Reslut, OutputFileName);
                break;
            }

            case ("nothing"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("prewitt"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[3] == "y")
                    {
                        ImageProcessing.Prewitt(image, "y");
                    }
                    if (args[3] == "x")
                    {
                        ImageProcessing.Prewitt(image, "x");
                    }
                }
                else
                {
                    ImageProcessing.Prewitt(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("invert"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.InvertImage(image);
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("sobel"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[3] == "y")
                    {
                        ImageProcessing.Sobel(image, "y");
                    }
                    if (args[3] == "x")
                    {
                        ImageProcessing.Sobel(image, "x");
                    }
                }
                else
                {
                    ImageProcessing.Sobel(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("mirror"): {
                if (args.Length >= 4)
                {
                    ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                    if (args[3] == "y")
                    {
                        ImageProcessing.FlipImageY(image);
                    }
                    if (args[3] == "x")
                    {
                        ImageProcessing.FlipImageX(image);
                    }
                    ImageIO.ImageToFile(image, OutputFileName);
                }
                break;
            }

            case ("roberts"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args.Length >= 4)
                {
                    if (args[3] == "1")
                    {
                        ImageProcessing.Roberts(image, 1);
                    }
                    if (args[3] == "2")
                    {
                        ImageProcessing.Roberts(image, 2);
                    }
                }
                else
                {
                    ImageProcessing.Roberts(image);
                }
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("rotate"):
            {
                if (args.Length < 5)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                if (args[3] == "cw")
                {
                    if (args[4] == "90")
                    {
                        ImageProcessing.RotateCw90(ref image);
                    }
                    if (args[4] == "180")
                    {
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                    }
                    if (args[4] == "270")
                    {
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                    }
                }
                else if (args[3] == "ccw")
                {
                    if (args[4] == "90")
                    {
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                    }
                    if (args[4] == "180")
                    {
                        ImageProcessing.RotateCw90(ref image);
                        ImageProcessing.RotateCw90(ref image);
                    }
                    if (args[4] == "270")
                    {
                        ImageProcessing.RotateCw90(ref image);
                    }
                }
                ImageIO.ImageToFile(image, OutputFileName);
            }
            break;

            case ("gauss"): {
                if (args.Length < 4)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.Gauss(ref image, float.Parse(args[3]));
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("median"):
            {
                if (args.Length < 4)
                {
                    return;
                }
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.Median(image, Int32.Parse(args[3]));
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            case ("gabor"):
            {
                ColorFloatImage image = ImageIO.FileToColorFloatImage(InputFileName);
                ImageProcessing.gabor(ref image, Single.Parse(args[3]), Single.Parse(args[4]), Single.Parse(args[5]), Single.Parse(args[6]), Single.Parse(args[7]));
                ImageIO.ImageToFile(image, OutputFileName);
                break;
            }

            default: break;
            }
            //GrayscaleFloatImage image = ImageIO.FileToGrayscaleFloatImage(InputFileName);
            //FlipImage(image);
        }
コード例 #12
0
ファイル: Compare.cs プロジェクト: dormouses/fur
        public static void Compare_metrik(string name1, string name2, int type, int corresp, float th, PointPairList list, int quant = -1)
        {
            StreamReader file1, file2;

            if (type == 0)
            {
                file1 = new StreamReader("ans_lbp" + name1 + ".txt");
                file2 = new StreamReader("ans_lbp" + name2 + ".txt");
            }
            else
            {
                file1 = new StreamReader(name1 + ".key");
                file2 = new StreamReader(name2 + ".key");
            }
            var lbp1 = new List <Point_pc>();
            var lbp2 = new List <Point_pc>();

            if (type == 0)
            {
                ReadLPC(file1, lbp1, quant);
                ReadLPC(file2, lbp2, quant);
            }
            else
            {
                ReadSIFT(file1, lbp1);
                ReadSIFT(file2, lbp2);
            }

            List <float> xp1 = new List <float>();
            List <float> xp2 = new List <float>();
            List <float> yp1 = new List <float>();
            List <float> yp2 = new List <float>();

            int r = 0;
            int l = 0;

            for (int i = 0; i < lbp1.Count; i++)
            {
                float cx1 = lbp1[i].x;
                float cy1 = lbp1[i].y;

                lbp2.Sort((x, y) =>
                {
                    double dx = Diff(x.lbp, lbp1[i].lbp);
                    double dy = Diff(y.lbp, lbp1[i].lbp);
                    if (dx > dy)
                    {
                        return(-1);
                    }
                    if (dy > dx)
                    {
                        return(1);
                    }
                    return(0);
                });


                for (int j = lbp2.Count - 1, n = 1; j > 0; j--, n++)
                {
                    float cx2 = lbp2[j].x;
                    float cy2 = lbp2[j].y;
                    float mmm = Diff(lbp2[j].lbp, lbp1[i].lbp);

                    /*  double th;
                     * if (type == 1)
                     *    th = 20000;
                     * else
                     *    th = 0.5;*/
                    Console.WriteLine(mmm.ToString() + ' ' + th.ToString());
                    if (mmm < th)
                    {
                        // Console.WriteLine("sdf");
                        if (Math.Abs(cx2 - (256 - cy1)) < PixTh && Math.Abs(cy2 - cx1) < PixTh)
                        {
                            r++;
                            xp1.Add(cx1);
                            yp1.Add(cy1);
                            xp2.Add(cx2);
                            yp2.Add(cy2);
                        }
                        else
                        {
                            l++;
                        }
                    }
                    break;
                }
            }


            list.Add((float)l / (float)(r + l), (float)r / corresp);

            var    img1 = ImageIO.FileToGrayscaleFloatImage(name1 + ".bmp");
            var    img2 = ImageIO.FileToGrayscaleFloatImage(name2 + ".bmp");
            string metr = "";

            if (type == 0)
            {
                metr = "_us_";
            }
            else
            {
                metr = "_sift_";
            }
            count++;
            if (count % 10 == 0)
            {
                Extra.Draw_Comparasion(img1, img2, xp1, yp1, xp2, yp2, "_+lbp" + name1 + "_and_" + name2 + metr + "th" + th.ToString() + ".bmp");
            }
        }