Example #1
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();
 }