public static TVL1Args Parse(string[] args) { var o = new TVL1Args(); int len = args.Length; var fileList = new List <string>(); for (int a = 0; a < len; a++) { string c = args[a]; if (c == "-o" && ++a < len) { o.dst = args[a]; } else if (c == "-l" && ++a < len) { if (!Helpers.TryParse(args[a], c, out o.lambda, double.TryParse)) { return(null); } } else if (c == "-n" && ++a < len) { if (!Helpers.TryParse(args[a], c, out o.niters, int.TryParse)) { return(null); } } else { fileList.Add(args[a]); } } o.srcList = fileList; return(o); }
public static void TVL1(TVL1Args args) { var observations = new List <Mat>(); foreach (string s in args.srcList) { Console.WriteLine("Reading image " + s); var imgData = CvInvoke.Imread(s, ImreadModes.AnyColor); observations.Add(imgData); } var outData = new Mat(); Console.WriteLine("Denoising using " + nameof(TVL1)); CvInvoke.DenoiseTVL1(observations.ToArray(), outData, args.lambda.Value, args.niters.Value); Console.WriteLine("Saving " + args.dst); outData.Bitmap.Save(args.dst); }
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; //} }