Ejemplo n.º 1
0
        public static double EvaluateW(UnmanagedImage image)
        {
            byte[,] pixels = image.GetPixels();
            double aggregate = 0;

            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    aggregate += pixels[i, j];
                }
            }

            aggregate = Math.Pow(width * height, -1) * aggregate;

            double aggregate2 = 0;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    aggregate2 += Math.Pow((pixels[i, j] - aggregate), 2);
                }
            }


            return((4D / (width * height * Math.Pow(255, 2))) * aggregate2);
        }
Ejemplo n.º 2
0
        private static Bitmap FusionProcessing(Bitmap image,
                                               IEnumerable <AlgorithmInfo> algorithms,
                                               IEnumerable <EvaluationResult> algoritmsScores)
        {
            double totalScore = algoritmsScores.Sum(x => x.AlgorithScore);
            var    results    = new Dictionary <double, byte[, ]>();

            foreach (var score in algoritmsScores)
            {
                AlgorithmInfo algorithmInfo = algorithms.Where(x => x.CustomName == score.AlgorithCustomName).Single();
                var           algorithm     = AppFacade.DI.Container.Resolve <IAlgorithm>(algorithmInfo.AlgorithName);
                algorithm.SetParameters(algorithmInfo.Parameters);
                algorithm.Input = new AlgorithmInput(image);
                UnmanagedImage result = algorithm.ProcessData().Image;
                results.Add(score.AlgorithScore / totalScore, result.GetPixels());
            }

            UnmanagedImage fusionImage =
                UnmanagedImage.FromManagedImage(new Bitmap(image.Width, image.Height, image.PixelFormat));

            var fusionBytes = new byte[image.Width, image.Height];

            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    double level = results.Sum(keyValuePair => (keyValuePair.Key * keyValuePair.Value[i, j]));
                    fusionBytes[i, j] = (byte)level;
                }
            }

            fusionImage.SetPixels(fusionBytes);
            return(fusionImage.ToManagedImage());
        }
Ejemplo n.º 3
0
        public static double EvaluateM(UnmanagedImage image)
        {
            byte[,] pixels = image.GetPixels();
            var stats        = new ImageStatistics(image);
            var minGrayLevel = (byte)stats.Gray.Min;
            var maxGrayLevel = (byte)stats.Gray.Max;

            return((double)(maxGrayLevel - minGrayLevel) / (double)(maxGrayLevel + minGrayLevel));
        }
Ejemplo n.º 4
0
        public static double EvaluateLocallyW(UnmanagedImage image)
        {
            byte[,] pixels = image.GetPixels();

            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            double aggregate = 0;

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    aggregate += Math.Pow((pixels[i, j] - pixels[i + 1, j]), 2);
                }
            }

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height - 1; j++)
                {
                    aggregate += Math.Pow((pixels[i, j] - pixels[i, j + 1]), 2);
                }
            }

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < height - 1; j++)
                {
                    aggregate += Math.Pow((pixels[i, j] - pixels[i + 1, j + 1]), 2);
                }
            }

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 1; j < height; j++)
                {
                    aggregate += Math.Pow((pixels[i, j] - pixels[i + 1, j - 1]), 2);
                }
            }

            return((1D / (width * height * Math.Pow(255, 2))) * aggregate);
        }
Ejemplo n.º 5
0
        public static double EvaluateS(UnmanagedImage image)
        {
            byte[,] pixels = image.GetPixels();
            var    stats        = new ImageStatistics(image);
            var    minGrayLevel = (byte)stats.Gray.Min;
            var    maxGrayLevel = (byte)stats.Gray.Max;
            double aggregate    = 0;

            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    aggregate += pixels[i, j];
                }
            }

            aggregate = Math.Pow(width * height, -1) * aggregate;
            return((maxGrayLevel - minGrayLevel) / aggregate);
        }