private static void FillPoints(eTypeOFImage typeOfImage, ref MeshHolder[] meshpoints) { string[] s1MeshFiles; s1MeshFiles = Directory.GetFiles(dictPaths[typeOfImage], "*.txt"); meshpoints = new MeshHolder[s1MeshFiles.Length]; for (int jj = 0; jj < s1MeshFiles.Length; jj++) { meshpoints[jj] = new MeshHolder(); meshpoints[jj].meshList = new List <PointOnGrid>(); meshpoints[jj].FileName = s1MeshFiles[jj]; LoadMeshFile(s1MeshFiles[jj], ref meshpoints[jj].meshList); } }
private void SaveToImage(eTypeOFImage typeofimage, ref ushort[,] InputEOSArray, string FileNum) { string localPath = AppDomain.CurrentDomain.BaseDirectory; string resultsRawPath = localPath + "Results_" + TimeOfRun + "\\Raw" + Settings.ImagePaths[typeofimage]; Bitmap bmp; BitmapSource bmpSourceGray; if (!Directory.Exists(resultsRawPath)) { Directory.CreateDirectory(resultsRawPath); } string resultsBMPPath = localPath + "\\Results_" + TimeOfRun + "\\Bmp" + Settings.ImagePaths[typeofimage]; if (!Directory.Exists(resultsBMPPath)) { Directory.CreateDirectory(resultsBMPPath); } string resultsPNGPath = localPath + "\\Results_" + TimeOfRun + "\\PNG" + Settings.ImagePaths[typeofimage]; if (!Directory.Exists(resultsPNGPath)) { Directory.CreateDirectory(resultsPNGPath); } int Width = InputEOSArray.GetLength(1); int Height = InputEOSArray.GetLength(0); bmpSourceGray = Utils.ArrayToGrayBitmap(EOSArray); bmpSourceGray.SaveTo16bPNG(resultsPNGPath + "img_" + FileNum + ".png"); bmp = Utils.ArrayToBitmap(EOSArray, palette); bmp.Save(resultsBMPPath + "img_" + FileNum + ".bmp", ImageFormat.Bmp); byte[] by1EOSArray = new byte[EOSArray.Length * sizeof(ushort)]; Buffer.BlockCopy(EOSArray, 0, by1EOSArray, 0, by1EOSArray.Length); File.WriteAllBytes(resultsRawPath + Width + "x" + Height + "_img_" + FileNum + ".raw", by1EOSArray); }
private void GenerateShape(ref int GlobalFrmCnt, int ii, eTypeOFImage eType) { string sConsoleMessage = null; baseShape shape = null; List <LabelData> localLabelsList = null; string sOriginaleFileName = "na"; MeshHolder meshHolder; double ratio = 1; switch (eType) { case eTypeOFImage.TestEng: sConsoleMessage = "Created Engine for Test image "; //shape = new Cylinder(Settings.Geometries.GetEngRandomH(), Settings.Geometries.GetEngRandomW()); meshHolder = Settings.TestEngMeshPoints.RandomIndex(); shape = new ComplexShape(meshHolder.meshList, Settings.Temperatures.EngTemp, eShape.Engine); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTest; ratio = (1 - Settings.TrainValidateRatio); break; case eTypeOFImage.TestRV: sConsoleMessage = "Created RV for Test image "; meshHolder = Settings.TestRVMeshPoints.RandomIndex(); shape = new ComplexShape(meshHolder.meshList, Settings.Temperatures.RvTemp, eShape.RV); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTest; ratio = (1 - Settings.TrainValidateRatio); break; case eTypeOFImage.TrainingEng: sConsoleMessage = "Created Engine for Training image "; meshHolder = Settings.TrainEngMeshPoints.RandomIndex(); shape = new ComplexShape(meshHolder.meshList, Settings.Temperatures.EngTemp, eShape.Engine); //shape = new Cylinder(Settings.Geometries.GetEngRandomH(), Settings.Geometries.GetEngRandomW()); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTraining; ratio = Settings.TrainValidateRatio; break; case eTypeOFImage.TrainingRV: sConsoleMessage = "Created RV for Training image "; //shape = new Conus(Settings.Geometries.GetRVRandomH(), Settings.Geometries.GetRVRandomW()); meshHolder = Settings.TrainRVMeshPoints.RandomIndex(); shape = new ComplexShape(Settings.TrainRVMeshPoints.RandomIndex().meshList, Settings.Temperatures.RvTemp, eShape.RV); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTraining; ratio = Settings.TrainValidateRatio; break; case eTypeOFImage.ValidationEng: sConsoleMessage = "Created Engine for Validation image "; //shape = new Cylinder(Settings.Geometries.GetEngRandomH(), Settings.Geometries.GetEngRandomW()); meshHolder = Settings.ValidateEngMeshPoints.RandomIndex(); shape = new ComplexShape(meshHolder.meshList, Settings.Temperatures.EngTemp, eShape.Engine); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTraining; ratio = (1 - Settings.TrainValidateRatio); break; case eTypeOFImage.ValidationRV: sConsoleMessage = "Created RV for Validation image "; //shape = new Conus(Settings.Geometries.GetRVRandomH(), Settings.Geometries.GetRVRandomW()); meshHolder = Settings.ValidateRVMeshPoints.RandomIndex(); shape = new ComplexShape(meshHolder.meshList, Settings.Temperatures.RvTemp, eShape.RV); sOriginaleFileName = meshHolder.FileName; localLabelsList = lstLabelsTraining; ratio = (1 - Settings.TrainValidateRatio); break; } if (shape != null && sConsoleMessage != null) { Random rnd = new Random(DateTime.UtcNow.Millisecond); shape.Scale(Settings.ScaleFactors.Scale * rnd.NextDouble() + Settings.ScaleFactors.Offset); //dirty hack, i rely on the fact that only ComplexShape implements 2 arguments shape.Rotate(rnd.Next(1, 359), rnd.Next(1, 359)); shape.Shift(rnd.Next(-5, 5), rnd.Next(-5, 5)); RectangleF rect = RectangleF.Empty; EOSArray = new ushort[Height, Width]; //Choose random background (both real and generated) if (rnd.Next(0, 3) > 0) { AddRealBackGround(ref EOSArray); } else { AddRandomBackGround(ref EOSArray); } shape.Render(ref EOSArray, ref rect); DEP dep = new DEP(); RectangleF dummyRect = RectangleF.Empty; dep.Render(ref EOSArray, ref dummyRect); if (rect != RectangleF.Empty) { CreateLabel(GlobalFrmCnt, shape.GetShapeID(), rect, shape.area, localLabelsList, sOriginaleFileName); SaveToImage(eType, ref EOSArray, GlobalFrmCnt.ToString("0000")); Console.WriteLine(sConsoleMessage + ii + " out of " + ratio * NumberOfTotalImages); GlobalFrmCnt++; } else { GenerateShape(ref GlobalFrmCnt, ii, eType); } } }