/// <summary>Get a rainfall forecast for the specified station number.</summary> /// <param name="stationNumber">The SILO station number.</param> /// <returns>Stream of data.</returns> public Stream Get(int stationNumber, DateTime nowDate, bool rainOnly) { // Get SILO data and write to a temporary file. DateTime startDate = new DateTime(1981, 1, 1); MemoryStream dataStream = WeatherFile.ExtractMetStreamFromSILO(stationNumber, startDate, DateTime.Now); string siloFileName = GetTemporaryFileName(); string forecastFileName = null; try { File.WriteAllBytes(siloFileName, dataStream.ToArray()); ChangeToWorkingDirectory(); // Run the MatLab script over the temporary SILO file. POAMAforecast.Class1 forecast = new POAMAforecast.Class1(); MWArray metFile = new MWCharArray(siloFileName); MWArray rainfallOnly = new MWNumericArray((double)1); if (!rainOnly) rainfallOnly = new MWNumericArray((double)0); MWArray writeFiles = new MWNumericArray((double)1.0); MWArray startDay = new MWNumericArray(Convert.ToDouble(nowDate.Day)); MWArray startMonth = new MWNumericArray(Convert.ToDouble(nowDate.Month)); MWArray startYear = new MWNumericArray(Convert.ToDouble(nowDate.Year)); forecast.calsite(metFile, rainfallOnly, writeFiles, startDay, startMonth, startYear); forecastFileName = siloFileName.Replace(".sim", "") + "_" + nowDate.Year + ".sim"; // Get rid of temporary file. File.Delete(siloFileName); if (WebOperationContext.Current != null && WebOperationContext.Current.OutgoingRequest != null) WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; if (File.Exists(forecastFileName)) { // Read in the forecast data. byte[] bytes = File.ReadAllBytes(forecastFileName); return new MemoryStream(bytes); } else return null; } finally { if (File.Exists(siloFileName)) File.Delete(siloFileName); if (forecastFileName != null && File.Exists(forecastFileName)) File.Delete(forecastFileName); } }
public void TrainModel(string featureFilePath, string completeFeatureFilePath, List<double[]> featureVector) { int dataLength = featureVector[0].Length; double[] featureData = MatrixUtil.FlattenMatrix(featureVector); MWCharArray rgbdFile = new MWCharArray(featureFilePath); MWNumericArray newFeature = new MWNumericArray(dataLength, featureVector.Count, featureData); rgbdfea.rgbdfea rgbdfea = new rgbdfea.rgbdfea(); rgbdfea.appendFeature(rgbdFile, newFeature); TrainModel(completeFeatureFilePath); }
public double SetImage(double z_pos, Bitmap img) { double drec = 0d; try { byte[,] grayData = new byte[img.Height, img.Width]; for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { grayData[i, j] = img.GetPixel(j, i).B; } } Int32 stat = 1; MWNumericArray mwpos = z_pos; MWNumericArray matrix = grayData; MWCharArray method = "BREN"; int[] list = { 0, 0, 256, 256 }; MWArray roi = new MWNumericArray(list); MWArray rect = myDll2.fmeasure(matrix, method, roi); double[,] Temp1 = (double[, ])((MWNumericArray)rect).ToArray(MWArrayComponent.Real); dicValue.Add(z_pos, Temp1[0, 0]); drec = Temp1[0, 0]; } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } return(drec); }
static void Main(string[] args) { CropAnalyzer crop_analyzer = new CropAnalyzer(); MWStructArray result = new MWStructArray(); // LOAD CROP DATA String path = "C:\\Program Files\\NareTrends\\BandiCropAnalyzer\\application\\bandicrop_data.ini"; MWCharArray crop_inifile = path; MWStructArray crops_db = (MWStructArray)crop_analyzer.load_crop_data(crop_inifile); string crop_name = "STRAWBERRY"; // DO CROP ENVIRONMENT CHECK double temp = 4; double hum = 80; result = (MWStructArray)crop_env_checker(crops_db, temp, hum, crop_name); // PARSE RESULTS FOR DISPLAY int print_level = 2; // 0->1->2 : INCREASING VERBOSITY string result_out = parse_results(result, print_level); // PERFORM STATUS CHECK + CONTROL ACTION double temp_in = 4; double hum_in = 80; double temp_out = -3; double hum_out = 40; result = (MWStructArray)crop_env_controller(crops_db, crop_name, temp_in, hum_in, temp_out, hum_out); Console.WriteLine("\nPress any key to exit."); Console.ReadKey(); }
private void bgwMatlabGen_DoWork(object sender, DoWorkEventArgs e) { ArrayList lit = e.Argument as ArrayList; e.Result = true; try { MWNumericArray fc_Hz = (double)lit[0], chanUpdate_ms = (double)lit[1], polarMod = (double)lit[2], mediaPara = (double[])lit[3], angSpread_deg = (double)lit[4], chanMod = (double)lit[5]; MWCharArray traFilePath = lit[6] as string, launAnteFilePath = lit[7] as string, recvAnteFilePath = lit[8] as string, chanParaSavePath = lit[9] as string, chanSavePath = lit[10] as string; MWArray[] matlabRlt = aeroChan.AeroChanGenerate(2, fc_Hz, chanUpdate_ms, polarMod, mediaPara, angSpread_deg, chanMod, traFilePath, launAnteFilePath, recvAnteFilePath, chanParaSavePath, chanSavePath); if ((matlabRlt[0] as MWNumericArray).ToScalarInteger() != 0) { e.Result = false; lastError = matlabRlt[1].ToString(); return; } } catch (Exception ex) { e.Result = false; lastError = "调用Matlab失败!"; } }
public void LSB_JPG() { WatermarkEmbed.Class1 watermarkEmbed = new WatermarkEmbed.Class1(); string mat_image = fCarrier; string LSB_Message = fWatermark; MWCharArray mat_image_mw = mat_image; MWCharArray LSB_Message_mw = LSB_Message; MWArray[] argsMatImage = new MWArray[] { mat_image_mw, LSB_Message_mw }; try { watermarkEmbed.WatermarkEmbed(mat_image_mw, LSB_Message_mw); } catch { MessageBox.Show("嵌入失败!请注意是否选择了非JPG格式图片,或嵌入文本过长", "警告!"); return; } System.Drawing.Image img = System.Drawing.Image.FromFile("DCT_LSB.jpg"); System.Drawing.Image bmp = new System.Drawing.Bitmap(img); img.Dispose(); pictureBox4.Image = bmp; fMarked = "DCT_LSB.jpg"; pictureBox4.Image = bmp; pictureBox2.Image = bmp; }
private void PhaseRetrivalIteration(DataTable Dt, string SavePath) { if (Dt.NumUse() < 4) { Output("Please select at least four images, " + "including a focal image, a reference image and at least two median images."); return; } if (Dt.NumType("Focal") != 1) { Output("Please select one and only one focal image."); return; } if (Dt.NumType("Reference") != 1) { Output("Please select one and only one reference image."); return; } string FocalName = null; int FocalDist = 0; List <String> MedianName = new List <string>(); List <int> MedianDist = new List <int>(); string ExportName = null; foreach (DataRow Dr in Dt.Rows) { if (Dr["Type"].ToString() == "Focal") { FocalName = Dr.GetName(); FocalDist = int.Parse(Dr["Distance"].ToString()); } if (Dr["Type"].ToString() == "Median") { MedianName.Add(Dr.GetName()); MedianDist.Add(int.Parse(Dr["Distance"].ToString())); ExportName = "RetrievedPhase"; } if (Dr["Type"].ToString() == "Reference") { continue; } } MWCharArray MWMedianName = new MWCharArray(MedianName.ToArray()); MWNumericArray MWMedianDist = new MWNumericArray(1, MedianDist.Count, MedianDist.ToArray()); StreamWriter CancelWriter = new StreamWriter(SavePath + "\\Cancel.log"); CancelWriter.BaseStream.SetLength(0); CancelWriter.WriteLine("Continue"); CancelWriter.Dispose(); Mf.RetrieveReferencePhase(SavePath, ExportName, MWParameter, 10000, FocalName, FocalDist, MWMedianName, MWMedianDist); Token.ThrowIfCancellationRequested(); }
// METHOD TO DO CONTROL ACTION BASED ON STATUS OUTPUT public static MWStructArray crop_env_controller(MWStructArray crops_db, string crop, double temp_in, double hum_in, double temp_out, double hum_out) { Console.WriteLine("\n======================= CROP CONTROLLER OUTPUT ======================="); CropAnalyzer crop_controller = new CropAnalyzer(); // Initialize checkers String[] checker_names = { "vpd_check", "dewpoint_check", "crop_temp_check" }; MWStructArray checker_list = new MWStructArray(1, 1, checker_names); // Initialize required input: temp_c_in, rh_in, temp_c_out, rh_out MWNumericArray temp_c_in = null; MWNumericArray rh_in = null; MWNumericArray temp_c_out = null; MWNumericArray rh_out = null; // Initialize optional inputs (by pair): verbose, TRUE/FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val, dewtemp_offset, dewtemp_offset_val //MWCharArray vpd = "vpd", dewpoint = "dewpoint"; MWCharArray checkers = "checkers", verbose = "verbose", crop_name = "crop_name", crop_name_select = ""; MWCharArray vpd_min = "vpd_min", vpd_max = "vpd_max", dewtemp_offset = "dewtemp_offset"; MWLogicalArray TRUE = new MWLogicalArray(true), FALSE = new MWLogicalArray(false); MWNumericArray vpd_min_val = 0.5, vpd_max_val = 1.2, dewtemp_offset_val = 1.0; // initialize output struct fields - FOR REFERENCE String[] vpd_check_fields = { "type", "code", "state", "vpd", "vpd_min", "vpd_max", "hum_adj", "adjust_unit" }; String[] dewpoint_check_fields = { "type", "code", "state", "temp", "temp_dew", "dewtemp_offset", "adjust", "adjust_unit" }; String[] crop_temp_check_fields = { "type", "code", "state", "temp", "temp_min", "temp_max", "adjust", "adjust_unit" }; // Set checker options checker_list.SetField("vpd_check", TRUE); checker_list.SetField("dewpoint_check", TRUE); checker_list.SetField("crop_temp_check", TRUE); // Create struct for output MWStructArray control_action = new MWStructArray(); try { // Full usage: crop.env_check(crops, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list, vpd_min, vpd_min_val, vpd_max, vpd_max_val, verbose, FALSE); crop_name_select = crop; temp_c_in = temp_in; // deg Celsius rh_in = hum_in; // % temp_c_out = temp_out; // deg Celsius rh_out = hum_out; // % control_action = (MWStructArray)crop_controller.env_controller(crops_db, crop_name_select, temp_c_in, rh_in, temp_c_out, rh_out); Console.WriteLine("CONTROL ACTION: \n" + control_action); //Console.WriteLine("Press any key to exit."); //Console.ReadKey(); return(control_action); } catch { throw; } }
void GetdBwithDistance(double distance) { MWArray[] result = new MWArray[1]; MWCharArray file = new MWCharArray(fileSelected); MWNumericArray dist = new MWNumericArray(distance); result = plotSound.dBAtDistance(1, file, dist); textBox1.Text = result[0].ToString(); }
static void Main(string[] args) { CropAnalyzer crop_analyzer = new CropAnalyzer(); // Initialize checkers String[] checker_names = { "vpd_check", "dewpoint_check", "crop_temp_check" }; MWStructArray checker_list = new MWStructArray(1, 1, checker_names); // Initialize required input: temp_c_in, rh_in MWNumericArray temp_c_in = null; MWNumericArray rh_in = null; // Initialize optional inputs (by pair): verbose, TRUE/FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val, dewtemp_offset, dewtemp_offset_val //MWCharArray vpd = "vpd", dewpoint = "dewpoint"; MWCharArray checkers = "checkers", verbose = "verbose", crop_name = "crop_name", crop_name_select = ""; MWCharArray vpd_min = "vpd_min", vpd_max = "vpd_max", dewtemp_offset = "dewtemp_offset"; MWLogicalArray TRUE = new MWLogicalArray(true), FALSE = new MWLogicalArray(false); MWNumericArray vpd_min_val = 0.5, vpd_max_val = 1.2, dewtemp_offset_val = 1.0; // initialize output struct fields - FOR REFERENCE String[] vpd_check_fields = { "type", "code", "state", "vpd", "vpd_min", "vpd_max", "hum_adj", "adjust_unit" }; String[] dewpoint_check_fields = { "type", "code", "state", "temp", "temp_dew", "dewtemp_offset", "adjust", "adjust_unit" }; String[] crop_temp_check_fields = { "type", "code", "state", "temp", "temp_min", "temp_max", "adjust", "adjust_unit" }; // Set checker options checker_list.SetField("vpd_check", TRUE); checker_list.SetField("dewpoint_check", TRUE); checker_list.SetField("crop_temp_check", TRUE); // Load crop data String path = "C:\\Program Files\\NareTrends\\BandiCropAnalyzer\\application\\bandicrop_data.ini"; MWCharArray crop_inifile = path; MWStructArray crops = (MWStructArray)crop_analyzer.load_crop_data(crop_inifile); // Create struct for output MWStructArray result = new MWStructArray(); MWNumericArray result_code = null; try { // Full usage: crop.env_check(crops, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list, vpd_min, vpd_min_val, vpd_max, vpd_max_val, verbose, FALSE); crop_name_select = "STRAWBERRY"; temp_c_in = 3; // deg Celsius rh_in = 40; // % result = (MWStructArray)crop_analyzer.env_check(crops, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list); result_code = (MWNumericArray)result.GetField("code"); Console.WriteLine("RESULT CODE: " + result_code); Console.Write("\nPress any key to exit."); Console.ReadKey(); } catch { throw; } }
// METHOD IMPLEMENTING THE ENVIRONMENT CHECK ROUTINES public static MWStructArray crop_env_checker(MWStructArray crops_db, double temp, double hum, string crop) { Console.WriteLine("\n======================= ENVIRONMENT ANALYSIS ======================="); CropAnalyzer crop_analyzer = new CropAnalyzer(); // Initialize checkers String[] checker_names = { "vpd_check", "dewpoint_check", "crop_temp_check" }; MWStructArray checker_list = new MWStructArray(1, 1, checker_names); // Initialize required input: temp_c_in, rh_in MWNumericArray temp_c_in = null; MWNumericArray rh_in = null; // Initialize optional inputs (by pair): verbose, TRUE/FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val, dewtemp_offset, dewtemp_offset_val //MWCharArray vpd = "vpd", dewpoint = "dewpoint"; MWCharArray checkers = "checkers", verbose = "verbose", crop_name = "crop_name", crop_name_select = ""; MWCharArray vpd_min = "vpd_min", vpd_max = "vpd_max", dewtemp_offset = "dewtemp_offset"; MWLogicalArray TRUE = new MWLogicalArray(true), FALSE = new MWLogicalArray(false); MWNumericArray vpd_min_val = 0.5, vpd_max_val = 1.2, dewtemp_offset_val = 1.0; // initialize output struct fields - FOR REFERENCE String[] vpd_check_fields = { "type", "code", "state", "vpd", "vpd_min", "vpd_max", "hum_adj", "adjust_unit" }; String[] dewpoint_check_fields = { "type", "code", "state", "temp", "temp_dew", "dewtemp_offset", "adjust", "adjust_unit" }; String[] crop_temp_check_fields = { "type", "code", "state", "temp", "temp_min", "temp_max", "adjust", "adjust_unit" }; // Set checker options checker_list.SetField("vpd_check", TRUE); checker_list.SetField("dewpoint_check", TRUE); checker_list.SetField("crop_temp_check", TRUE); // Create struct for output MWStructArray result = new MWStructArray(); MWNumericArray result_code = null; try { // Full usage: crop.env_check(crops, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list, vpd_min, vpd_min_val, vpd_max, vpd_max_val, verbose, FALSE); crop_name_select = crop; temp_c_in = temp; // deg Celsius rh_in = hum; // % result = (MWStructArray)crop_analyzer.env_check(crops_db, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list); result_code = (MWNumericArray)result.GetField("code"); Console.WriteLine("RESULT CODE: " + result_code); //Console.WriteLine("Press any key to exit."); //Console.ReadKey(); return(result); } catch { throw; } }
public MWStructArray load_crop_db() { CropAnalyzer crop_analyzer = new CropAnalyzer(); // LOAD CROP DATA String path = "C:\\Program Files\\NareTrends\\BandiCropAnalyzer\\application\\bandicrop_data.ini"; MWCharArray crop_inifile = path; MWStructArray crops_db = (MWStructArray)crop_analyzer.load_crop_data(crop_inifile); return(crops_db); }
public void MWArray_GetField_Array_String_Input() { var f = "arrayfield"; Array value = Enumerable.Range(0, 42).Select(i => i.ToString()).ToArray(); var sa = new MWStructArray(new int[] { 1 }, new string[] { f }); var result = new MWCharArray(value); sa[f] = result; Assert.That(MWArrayExtensions.GetField(sa, f).Equals(result)); }
// DO CONTROL ACTION BASED ON ENVIRONMENT CHECKING OUTPUT public MWStructArray crop_env_controller(MWStructArray crops_db, string crop, DongState sensors) { Console.WriteLine("\n======================= CROP CONTROLLER OUTPUT ======================="); BandiCropAnalyzer.CropAnalyzer crop_controller = new BandiCropAnalyzer.CropAnalyzer(); // Initialize checkers String[] checker_names = { "vpd_check", "dewpoint_check", "crop_temp_check" }; MWStructArray checker_list = new MWStructArray(1, 1, checker_names); // Initialize optional inputs (by pair): verbose, TRUE/FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val, dewtemp_offset, dewtemp_offset_val //MWCharArray vpd = "vpd", dewpoint = "dewpoint"; MWCharArray checkers = "checkers", verbose = "verbose", crop_name = "crop_name", crop_name_select = ""; MWCharArray rh_bed = "rh_bed", co2_supply = "co2_supply", rain = "rain"; MWCharArray vpd_min = "vpd_min", vpd_max = "vpd_max", dewtemp_offset = "dewtemp_offset"; MWLogicalArray TRUE = new MWLogicalArray(true), FALSE = new MWLogicalArray(false); MWNumericArray vpd_min_val = 0.5, vpd_max_val = 1.2, dewtemp_offset_val = 1.0; // initialize output struct fields - FOR REFERENCE String[] vpd_check_fields = { "type", "code", "state", "vpd", "vpd_min", "vpd_max", "hum_adj", "adjust_unit" }; String[] dewpoint_check_fields = { "type", "code", "state", "temp", "temp_dew", "dewtemp_offset", "adjust", "adjust_unit" }; String[] crop_temp_check_fields = { "type", "code", "state", "temp", "temp_min", "temp_max", "adjust", "adjust_unit" }; // Set checker options checker_list.SetField("vpd_check", TRUE); checker_list.SetField("dewpoint_check", TRUE); checker_list.SetField("crop_temp_check", TRUE); // Create struct for output MWStructArray control_action = new MWStructArray(); try { // Full usage: crop.env_check(crops, temp_c_in, rh_in, crop_name, crop_name_select, checkers, checker_list, vpd_min, vpd_min_val, vpd_max, vpd_max_val, verbose, FALSE); crop_name_select = crop; MWNumericArray temp_c_in = sensors.temp_in; // deg Celsius MWNumericArray rh_in = sensors.hum_in; // % MWNumericArray temp_c_out = sensors.temp_out; // deg Celsius MWNumericArray rh_out = sensors.hum_out; // % MWNumericArray hum_bed = sensors.hum_bed; // % MWLogicalArray co2_state = sensors.co2_supply; // % MWLogicalArray rain_state = sensors.rain; // % return(control_action = (MWStructArray)crop_controller.env_controller(crops_db, crop_name_select, temp_c_in, rh_in, temp_c_out, rh_out, rh_bed, hum_bed, co2_supply, co2_state, rain, rain_state)); } catch { throw; } }
public void MWArray_GetField_Char_Input() { var f = "arrayfield"; char value = 'c'; var sa = new MWStructArray(new int[] { 1 }, new string[] { f }); var result = new MWCharArray(value); sa[f] = result; Assert.That(MWArrayExtensions.GetField(sa, f).Equals(result)); }
static void Main(string[] args) { Directory.SetCurrentDirectory(@"G:\"); POAMAforecast.Class1 d = new POAMAforecast.Class1(); MWArray metFile = new MWCharArray(@"Burnie.sim"); MWArray startMonth = new MWNumericArray((double) 6.0); MWArray startDay = new MWNumericArray((double) 1.0); MWArray rainOnly = new MWNumericArray((double)1.0); MWArray writeFiles = new MWNumericArray((double)1.0); MWArray lastYearOnly = new MWNumericArray((double)1.0); d.calsite(metFile, startMonth, startDay, rainOnly, writeFiles, lastYearOnly); }
private void buttonOK_Click(object sender, EventArgs e) { if ((listBoxImages.SelectedItem == null) || String.IsNullOrEmpty(listBoxImages.SelectedItem.ToString())) { return; } Cursor.Current = Cursors.WaitCursor; if (File.Exists("Ic_out.png")) { File.Delete("Ic_out.png"); } pictureBoxResult.Image = null; double factor1; double factor2; double threshold1; double threshold2; string folder; string file; double.TryParse(textBoxFactor1.Text, out factor1); double.TryParse(textBoxFactor2.Text, out factor2); double.TryParse(textBoxThreshold1.Text, out threshold1); double.TryParse(textBoxThreshold2.Text, out threshold2); folder = System.IO.Path.GetDirectoryName(listBoxImages.SelectedItem.ToString()) + @"\"; file = System.IO.Path.GetFileName(listBoxImages.SelectedItem.ToString()); double[] _threshold = new double[] { threshold1, threshold2 }; MWNumericArray threshold = new MWNumericArray(_threshold); MWNumericArray fudgeFactor1 = new MWNumericArray(factor1); MWNumericArray fudgeFactor2 = new MWNumericArray(factor2); MWCharArray path = new MWCharArray(folder); MWCharArray filename = new MWCharArray(file); ClassMedDetect medDetect = new ClassMedDetect(); MWArray MWResult = medDetect.func_med_detect(path, filename, threshold, fudgeFactor1, fudgeFactor2); pictureBoxResult.Image = Image.FromFile("Ic_out.png"); labelCautnTotal.Text = String.Format("Кол-во обнаруженных объектов: {0}", (double)((MWNumericArray)MWResult[1])); labelSquareTotal.Text = String.Format("Общая площадь объектов:: {0}", (double)((MWNumericArray)MWResult[2])); labelCountSelected.Text = String.Format("Кол-во выделенных объектов:: {0}", (double)((MWNumericArray)MWResult[3])); labelSquareSelected.Text = String.Format("Площадь выделенных объектов: {0}", (double)((MWNumericArray)MWResult[4])); Cursor.Current = Cursors.Default; MessageBox.Show("Расчет закончен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void Main(string[] args) { Directory.SetCurrentDirectory(@"G:\"); POAMAforecast.Class1 d = new POAMAforecast.Class1(); MWArray metFile = new MWCharArray(@"Burnie.sim"); MWArray startMonth = new MWNumericArray((double)6.0); MWArray startDay = new MWNumericArray((double)1.0); MWArray rainOnly = new MWNumericArray((double)1.0); MWArray writeFiles = new MWNumericArray((double)1.0); MWArray lastYearOnly = new MWNumericArray((double)1.0); d.calsite(metFile, startMonth, startDay, rainOnly, writeFiles, lastYearOnly); }
public void TrainModel(string featureFilePath, string completeFeatureFilePath, List <double[]> featureVector) { int dataLength = featureVector[0].Length; double[] featureData = MatrixUtil.FlattenMatrix(featureVector); MWCharArray rgbdFile = new MWCharArray(featureFilePath); MWNumericArray newFeature = new MWNumericArray(dataLength, featureVector.Count, featureData); rgbdfea.rgbdfea rgbdfea = new rgbdfea.rgbdfea(); rgbdfea.appendFeature(rgbdFile, newFeature); TrainModel(completeFeatureFilePath); }
/// <summary> /// Enhances the contrast of the image of this image processor /// </summary> /// <param name="C">Contrast factor falls in the interval [-1,+INF[</param> public void EnhanceContrast(double C) { try { MWArray path = new MWCharArray(originalImagePath); MWArray res = new MWCharArray(); res = IMC.contrast(path, C); undoStack.Push(new imageProcessorOperation("Brightness Enhancement", res.ToString())); NewImagePath = res.ToString(); } catch (Exception ex) { throw ex; } }
public double[,] Resize(double[,] matrix, double scale, ResizeMethod method) { try { var arr = new MWNumericArray(matrix); var s = new MWNumericArray(scale); var m = new MWCharArray(method.ToString()); return (double[,])_lib.Resize(arr, s, m).ToArray(); } catch (Exception ex) { MessageBox.Show(ex.Message, "TERS-MatlabApi"); return null; } }
public static double[] resultsForReranking; //stores the image number when images are categories covered by similarity matrix public static string matchClass() { //MessageBox.Show("match initialize"); MatchingClass matchtest = null; MWCharArray output = null; MWArray MWresult = null; matchtest = new MatchingClass(); //MessageBox.Show("start match"); MWresult = matchtest.build_matching_test_correct_csharp2(); output = (MWCharArray)MWresult[1, 1]; matchedClass = output.ToString(); rerankingImageName = -1; return(matchedClass); }
public IEnumerable<double> ManualInterp(IEnumerable<double> x, IEnumerable<double> y, IEnumerable<double> interpX, InterpMethods method) { var x0 = new MWNumericArray(x.ToArray()); var y0 = new MWNumericArray(y.ToArray()); var xi = new MWNumericArray(interpX.ToArray()); var m = new MWCharArray(method.ToString()); try { var ret = (double[,])_lib.Interp1(x0, y0, xi, m).ToArray(); return selectVectorFormMatrix(ret, 0, 0).Zip(y, (baseline, origin) => origin - baseline); } catch (Exception ex) { MessageBox.Show(ex.Message, "TERS-MatlabLib"); return null; } }
public void getGasCalculate(string database, string tableName, double l, double r, double t, out double dist, out double tick) { MWCharArray dataPath = new MWCharArray(database); MWCharArray table = new MWCharArray(tableName); MWNumericArray length = new MWNumericArray(l); MWNumericArray radius = new MWNumericArray(r); MWNumericArray thickness = new MWNumericArray(t); MWArray[] argsOut = new MWArray[2]; MWArray[] argsIn = new MWArray[] { dataPath, table, length, radius, thickness }; m2CClass.GasLeak(2, ref argsOut, argsIn); MWNumericArray distance = argsOut[0] as MWNumericArray; MWNumericArray timeTick = argsOut[1] as MWNumericArray; dist = (double)distance.ToScalarDouble(); tick = (double)timeTick.ToScalarDouble(); }
void graph(string fileName) { //chart1.Series["Data"].Points.AddXY(; //chart1.Series["Data"].ChartType = // SeriesChartType.FastLine; //chart1.Series["Data"].Color = Color.Red; label5.Visible = true; try { plotSound = new soundPlotter.PlotSound(); } catch (Exception e) { Console.WriteLine(e.InnerException); } try { MWCharArray input = new MWCharArray(fileName); fileSelected = fileName; MWArray[] result = new MWArray[2]; result = plotSound.plotSound(2, input); textBox3.Text = result[0].ToString(); //double tempo = Convert.ToDouble(result[1].ToString()); textBox4.Text = Convert.ToDouble(result[1].ToString()).ToString(); } catch (Exception e) { Console.WriteLine(e.InnerException); } string[] temp = fileName.Split('\\'); label6.Text = temp[temp.Length - 1]; label5.Visible = false; IntPtr foundwindow = FindWindow("sunawtframe", "figure 2"); SetParent(foundwindow, panel1.Handle); MoveWindow(foundwindow, -5, -80, panel1.Width + 10, panel1.Height + 90); foundwindow = FindWindow("sunawtframe", "figure 1"); SetParent(foundwindow, panel2.Handle); MoveWindow(foundwindow, -5, -80, panel2.Width + 10, panel2.Height + 90); //SetWindowPos(foundwindow, -2, 0, 0, 800, 600, 0x0040); //SetWindowLong(foundwindow, GWL_STYLE, WS_SYSMENU); }
public double[,] Fqfilter(double[,] matrix, FqfilterFlag flag, FqfilterType type, int D0, int n) { try { if (D0 <= 0) throw new ArgumentException("Parameter D0 must be positive."); var arr = new MWNumericArray(matrix); MWCharArray f = new MWCharArray(flag.ToString()), t = new MWCharArray(type.ToString()); var d = new MWNumericArray(D0); var nn = new MWNumericArray(n); return (double[,])_lib.fqfilter(2, arr, f, t, d, nn)[0].ToArray(); } catch (Exception ex) { MessageBox.Show(ex.Message, "TERS-MatlabLib"); return null; } }
private void MathNetTest_Click(object sender, RoutedEventArgs e) { MWNumericArray missTone = new int[] { 1000, 2000 }; MWCharArray fileDir = "E:\\JiweiSung\\VisualStudioProject2017\\Code-For-Practice\\"; MWCharArray fileName = "NoNative"; MWNumericArray dslProfile = 4; MWNumericArray upLimitPar = 16; MWNumericArray lowLimitPar = 15; MWNumericArray maxVoltage = 1; MWNumericArray ifftSize = 65536; MWNumericArray bitWidth = 16; MWNumericArray instrPar = 16; MatlabData.N8241aWfm n8241aData = new MatlabData.N8241aWfm(); MWArray[] realPar = n8241aData.DslWfmData(2, dslProfile, missTone, upLimitPar, lowLimitPar, maxVoltage, fileDir, fileName, ifftSize, bitWidth, instrPar); Log(1, realPar[0].ToString()); Log(1, realPar[1].ToString()); }
public FrequencyInfo offlineAnalyze(string fileName) { Console.WriteLine("Start analyzing offline file:" + fileName); MWCharArray filename = fileName; MWArray[] argsIn = new MWArray[] { filename }; MWArray[] result = new MWArray[3]; vitalSignsExtract.offlineVitalSignsExtract(3, ref result, argsIn); double[,] temp = (double[, ])result[0].ToArray(); int num = temp.GetLength(1); double[] breath = new double[num]; double[] heartbeat = new double[num]; double[] t = new double[num]; for (int i = 0; i < num; i++) { breath[i] = temp[1, i]; heartbeat[i] = temp[2, i]; t[i] = temp[0, i]; } double meanBreath = (double)(MWNumericArray)result[1]; double meanHeartbeat = (double)(MWNumericArray)result[2]; FrequencyInfo frequency = new FrequencyInfo(breath, heartbeat, t, meanBreath, meanHeartbeat, 0); /* * double[,] time = (double[,])result[1].ToArray(); * int num = frequency.GetLength(1); * int[] breath = new int[num]; * heartbeat = new int[num]; * t = new double[num]; * for(int i = 0; i < num; i++) * { * breath[i] = (int)frequency[0, i]; * heartbeat[i] = (int)frequency[1, i]; * t[i] = time[0, i]; * } * return breath;*/ Console.WriteLine("Analysis ends"); return(frequency); //throw new NotImplementedException(); }
//static steelnet.Calculate sc = new Calculate(); /// <summary> /// /// </summary> /// <param name="steeltype">"net1E0669"</param> /// <param name="inputdata">{ 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.0022 }</param> /// <returns></returns> public double[] steelcal_double(string steeltype, double[] input) { double[,] inputdata = new double[, ] { { input[0] }, { input[1] }, { input[2] }, { input[3] }, { input[4] }, { input[5] }, { input[6] }, { input[7] } }; MWCharArray calname = steeltype; //double[] inputd = { 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.0022 }; MWNumericArray x = (MWNumericArray)inputdata; MWNumericArray d = (MWNumericArray)sc.calculate(calname, x); //MWNumericArray x2 = (MWNumericArray)d; double[,] ddout = (double[, ])d.ToArray(MWArrayComponent.Real); double[] result = new double[ddout.GetLength(0)];//根据第一列长度生成结果数组; for (int i = 0; i < ddout.GetLength(0); i++) { result[i] = ddout[i, 0]; } return(result); }
public double[,] Spfilter(double[,] matrix, SpfilterType type, int m, int n, int para) { try { var arr = new MWNumericArray(matrix); var t = new MWCharArray(type.ToString()); var mm = new MWNumericArray(m); var nn = new MWNumericArray(n); var p = new MWNumericArray(para); if (type == SpfilterType.chmean || type == SpfilterType.artimmed) return (double[,])_lib.spfilt(arr, t, mm, nn, para).ToArray(); else return (double[,])_lib.spfilt(arr, t, mm, nn).ToArray(); } catch (Exception ex) { MessageBox.Show(ex.Message, "TERS-MatlabLib"); return null; } }
static void Main(string[] args) { CropAnalyzer crop = new CropAnalyzer(); // Initialize required input: temp_c_in, rh_in MWNumericArray temp_c_in = null; MWNumericArray rh_in = null; // Initialize optional input (by pair): verbose, TRUE/FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val MWCharArray verbose = "verbose", vpd_min = "vpd_min", vpd_max = "vpd_max"; MWLogicalArray TRUE = new MWLogicalArray(true), FALSE = new MWLogicalArray(false); MWNumericArray vpd_min_val = 0.5, vpd_max_val = 1.2; // initialize output struct fields String[] result_fields = { "type", "code", "state", "vpd", "vpd_min", "vpd_max", "hum_adj", "adjust_unit" }; MWStructArray result = new MWStructArray(1, result_fields.Count(), result_fields); //MWStructArray result = new MWStructArray(); //MWNumericArray result_code = null; try { // Full usage: moisture.vpd_check(temp_c_in, rh_in, verbose, FALSE, vpd_min, vpd_min_val, vpd_max, vpd_max_val); temp_c_in = 25; // deg Celsius rh_in = 70; // % vpd_min_val = 0.5; // kPa vpd_max_val = 1.2; // kPa result = (MWStructArray)crop.vpd_check(temp_c_in, rh_in, verbose, TRUE, vpd_min, vpd_min_val, vpd_max, vpd_max_val); result_code = (MWNumericArray)result.GetField("code"); Console.WriteLine("RESULT CODE: " + result_code); Console.Write("\nPress any key to exit."); Console.ReadKey(); } catch { throw; } }
public void ROBUST_QIM() { Embed2.Class1 embed2 = new Embed2.Class1(); MWCharArray src_img = fCarrier; MWCharArray watermark_txt = fWatermark; try { embed2.Embed2(src_img, watermark_txt, len, i, j, seed); } catch { MessageBox.Show("嵌入失败!请检查图片与水印", "警告"); } fMarked = "ROBUST_QIM.bmp"; System.Drawing.Image img = System.Drawing.Image.FromFile("ROBUST_QIM.bmp"); System.Drawing.Image bmp = new System.Drawing.Bitmap(img); img.Dispose(); pictureBox4.Image = bmp; pictureBox2.Image = bmp; }
public void LSB_DCT() { visible_DCT.Class1 visible_dct = new visible_DCT.Class1(); string src = fCarrier; string watermark = fWatermark; MWCharArray src_mw = src; MWCharArray watermark_mw = watermark; try { visible_dct.visible_DCT(src_mw, watermark_mw); } catch { MessageBox.Show("嵌入失败,请尝试其他图片", "提示"); } System.Drawing.Image img = System.Drawing.Image.FromFile("visible_DCT.bmp"); System.Drawing.Image bmp = new System.Drawing.Bitmap(img); img.Dispose(); pictureBox4.Image = bmp; fMarked = "visible_DCT.bmp"; }
public Image(string path) { MWNumericArray descriptor = null; MWCharArray mw_path; try { mw_path = new MWCharArray(path); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); return; } Loader Loader = new Loader(); image = Loader.loadimage(mw_path); descriptor = (MWNumericArray)image; try { Array = new ImageArray((double[,])descriptor.ToArray(MWArrayComponent.Real)); } catch (InvalidCastException exc) { descriptor = null; mw_path = null; Loader = null; GC.Collect(); return; } Height = Array.Array.GetLength(0); Width = Array.Array.GetLength(1); GetBitmap(); descriptor = null; mw_path = null; Loader = null; GC.Collect(); }
public static double[,] cont_wavelet_transform(double[] input_signal, double[] scale, string wavelet) { CWT.CWT_Class c = new CWT.CWT_Class(); int numSamples = input_signal.Length;// SPM.Count; MWNumericArray data = new MWNumericArray(MWArrayComplexity.Real, MWNumericType.Double, numSamples); MWNumericArray scale_m = new MWNumericArray(MWArrayComplexity.Real, MWNumericType.Double, scale.Length); MWCharArray name = new MWCharArray(wavelet); for (int idx = 1; idx <= scale.Length; idx++) { scale_m[idx] = scale[idx - 1]; } // Initialize data for (int idx = 1; idx <= numSamples; idx++) { data[idx] = input_signal[idx - 1]; } MWNumericArray res = (MWNumericArray)c.PerformCWT(data, scale_m, name); double[,] coeffs = (double[,])(res.ToArray(MWArrayComponent.Real)); return coeffs; }