public static void NlMeans(NlMeansArgs args) { Console.WriteLine("Reading image " + args.src); var imgData = CvInvoke.Imread(args.src, ImreadModes.AnyColor); var outData = new Mat(imgData.Size, imgData.Depth, imgData.NumberOfChannels); Console.WriteLine("Denoising using " + nameof(NlMeans)); CvInvoke.FastNlMeansDenoising(imgData, outData, (float)args.h, args.templateWindowSize, args.searchWindowSize); Console.WriteLine("Saving " + args.dst); outData.Bitmap.Save(args.dst); }
public static NlMeansArgs Parse(string[] args) { var o = new NlMeansArgs(); int len = args.Length; for (int a = 0; a < len; a++) { string c = args[a]; if (c == "-h" && ++a < len) { if (!Helpers.TryParse(args[a], c, out o.h, double.TryParse)) { return(null); } } else if (c == "-t" && ++a < len) { if (!Helpers.TryParse(args[a], c, out o.templateWindowSize, int.TryParse)) { return(null); } } else if (c == "-s" && ++a < len) { if (!Helpers.TryParse(args[a], c, out o.searchWindowSize, int.TryParse)) { return(null); } } else { if (o.src == null) { o.src = args[a]; } else if (o.dst == null) { o.dst = args[a]; } } } return(o); }
static void MainMain(string[] args) { //not sure how beneficial this is CvInvoke.RedirectError(CvInvoke.CvErrorHandlerIgnoreError, IntPtr.Zero, IntPtr.Zero); //string inFile = null; //inFile = fileList.FirstOrDefault(); //if (String.IsNullOrWhiteSpace(inFile)) { // Console.WriteLine("Missing input file"); // return; //} //if(String.IsNullOrEmpty(outFile)) //{ // if (fileList.Count > 1) { // outFile = fileList[1]; // } else { // outFile = Path.GetFileNameWithoutExtension(inFile) // +".out"+Path.GetExtension(inFile); // } //} if (Method == MethodType.NlMeans) { var ments = NlMeansArgs.Parse(args); Methods.NlMeans(ments); } else if (Method == MethodType.NlMeansColored) { var ments = NlMeansColoredArgs.Parse(args); Methods.NlMeansColored(ments); } else if (Method == MethodType.Dct) { var ments = DctArgs.Parse(args); if (!ments.sigma.HasValue) { Console.WriteLine("option -s is required"); return; } Methods.Dct(ments); } else if (Method == MethodType.TVL1) { var ments = TVL1Args.Parse(args); if (!ments.lambda.HasValue) { Console.WriteLine("option -l is required"); return; } if (!ments.niters.HasValue) { Console.WriteLine("option -n is required"); return; } Methods.TVL1(ments); } //else if (Method == MethodType.DFTForward) { // Methods.DFTForward(inFile,outFile); //} //else if (Method == MethodType.DFTInverse) { // if (fileList.Count < 2 || fileList[0] == null || fileList[1] == null) { // Console.WriteLine("your must specify both a magnitude image and a phase image"); // return; // } // if (fileList.Count > 2) { // outFile = fileList[2]; // } else { // outFile = Path.GetFileNameWithoutExtension(fileList[0])+".inv.png"; // } // // Debug.WriteLine("mi="+m6mi.GetValueOrDefault() // +" mx="+m6mx.GetValueOrDefault() // +" pi="+m6pi.GetValueOrDefault() // +" px="+m6px.GetValueOrDefault() // ); // // if (!m6mi.HasValue || !m6mx.HasValue || !m6pi.HasValue || !m6px.HasValue) { // Console.WriteLine("you must specify magnitude and phase ranges"); // return; // } // // Methods.DFTInverse(fileList,outFile,m6mi.Value,m6mx.Value,m6pi.Value,m6px.Value); // return; //} }