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(); }
public async Task<ProcessingResult> ProcessPhotoAsync(string filename) { using(var wand = new MagickWand()) { var srcFile = _pathHelper.GetSourceFilePath(filename); if(_rawConverter.IsRawFile(srcFile)) { var conversionResult = await _rawConverter.ConvertAsync(srcFile); wand.ReadImage(conversionResult.OutputFile); File.Delete(conversionResult.OutputFile); } else { wand.ReadImage(srcFile); } wand.AutoOrientImage(); wand.AutoLevelImage(); wand.StripImage(); var path = Path.Combine(Path.GetDirectoryName(srcFile), "review", $"{Path.GetFileNameWithoutExtension(filename)}.jpg"); wand.WriteImage(path, true); } return null; }
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(); }
public void AutoLevelTest() { MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { wand.AutoLevelImage(); WriteImage("auto_level", file, new string[] { }, wand); } } MagickWandEnvironment.Terminus(); }