Ejemplo n.º 1
0
        void Run()
        {
            MagickWandEnvironment.Genesis();

            var qr = (double)MagickWandEnvironment.QuantumRange;

            WriteLine(new string[] { "Quantum Range", $"{qr}" });
            Console.WriteLine();
            WriteLine(new string[] { "Image Name", "Mean", "StdDev", "Mean (pct)", "StdDev (pct)", "Kurtosis", "Skew" });

            foreach (var file in Directory.GetFiles(_opts.PhotoRoot))
            {
                double mean, stddev, kurtosis, skewness;

                using (var wand = new MagickWand(file))
                {
                    wand.AutoLevelImage();
                    wand.GetImageChannelMean(ChannelType.AllChannels, out mean, out stddev);
                    wand.GetImageChannelKurtosis(ChannelType.AllChannels, out kurtosis, out skewness);

                    WriteLine(new string[] { $"{Path.GetFileName(file)}", $"{mean}", $"{stddev}", $"{mean / qr}", $"{stddev / qr}", $"{kurtosis}", $"{skewness}" });
                }
            }

            MagickWandEnvironment.Terminus();
        }
Ejemplo n.º 2
0
 void PrintStats(string file, MagickWand wand)
 {
     double mean, stddev, kurtosis, skewness;
     
     wand.GetImageChannelMean(ChannelType.AllChannels, out mean, out stddev);
     wand.GetImageChannelKurtosis(ChannelType.AllChannels, out kurtosis, out skewness);
     
     Console.WriteLine($"{Path.GetFileName(file)}\t{mean}\t{stddev}\t{kurtosis}\t{skewness}");
 }
Ejemplo n.º 3
0
 public void ComposedTest()
 {
     var contrastRatioThreshold = 0.5;
     var tooContrastyThreshold = 1.9;
     
     MagickWandEnvironment.Genesis();
     
     PrintStatsHeader();
     
     foreach(var file in _files)
     {
         using(var wand = new MagickWand(file))
         {
             double mean, stddev;
             
             wand.GetImageChannelMean(ChannelType.AllChannels, out mean, out stddev);
             
             PrintStats(file, wand);
             
             wand.AutoLevelImage();
             
             var contrastRatio = stddev / mean;
             var contrastyRatio = stddev / 10000;
             
             if(contrastRatio < contrastRatioThreshold)
             {
                 var saturationAmount = Convert.ToInt32((contrastRatioThreshold - contrastRatio) * 100) * 4;
                 
                 // limit the saturation adjustment to 20%
                 if(saturationAmount > 20)
                 {
                     saturationAmount = 20;
                 }
                 
                 saturationAmount += 100;
                 
                 Console.WriteLine("modulating by: " + saturationAmount);
                 
                 // 100 = don't adjust brightness
                 // 300 = don't rotate hue
                 wand.ModulateImage(100, saturationAmount, 300);
             }
             else if(contrastyRatio > tooContrastyThreshold)
             {
                 Console.WriteLine("attempting to reduce contrast");
                 wand.SigmoidalContrastImage(true, 2, 0);  // smooth brightness/contrast
             }
             
             wand.UnsharpMaskImage(0, 0.7, 0.7, 0.008);  // sharpen
             
             WriteImage("composed", file, new string[] { }, wand);
         }
     }
     
     MagickWandEnvironment.Terminus();
 }