private string BinarizeImage(string sourcepath, int imageWidth, int imageHeight, string destinationPath, string name) { string binaryImage; Binarizer imageBinarizer = new Binarizer(200, 200, 200, imageWidth, imageHeight); //binaryImage = $"{testName}.txt"; if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } string _destinationPath = Path.Combine(destinationPath, $"{name}.jpg"); string _sourcePath = Path.Combine(sourcepath, $"{name}.jpg"); if (File.Exists(_destinationPath)) { File.Delete(_destinationPath); } imageBinarizer.CreateBinary(_sourcePath, _destinationPath); binaryImage = imageBinarizer.GetBinary(_sourcePath); // Console.WriteLine(binaryImage); //int[] vector = return(_destinationPath); }
/// <summary> /// Returns Binarized Image in integer array and creates file of Binarized Image /// </summary> /// <param name="imageName">Name of Image to be binarized</param> /// <param name="height">Height of Binarized Image</param> /// <param name="width">Width of Binarized Image</param> /// <returns></returns> public int[] ReadImageData(String imageName, int height, int width) { Binarizer bizer = new Binarizer(targetHeight: height, targetWidth: width); var imgName = Path.Combine(Path.Combine(AppContext.BaseDirectory, "Images"), imageName); bizer.CreateBinary(imgName, Path.Combine(Path.Combine(AppContext.BaseDirectory, "Output"), $"bin-{imageName}.txt")); var binaryString = bizer.GetBinary(imgName); int[] intArray = new int[height * width]; int j = 0; for (int i = 0; i < binaryString.Length; i++) { if (binaryString[i].Equals('0')) { intArray[j] = 0; j++; } else if (binaryString[i].Equals('1')) { intArray[j] = 1; j++; } } return(intArray); }
public void BinarizerTest() { string trainingImagesPath = Path.Combine(Path.Combine(AppContext.BaseDirectory, "MLPerceptron"), "TrainingImages"); Binarizer bizer = new Binarizer(); bizer.CreateBinary(Path.Combine(trainingImagesPath, "1 (168).jpeg"), "binary.txt"); }
public void BinarizeImageTest(String sourcePath, String destinationPath) { Binarizer imageBinarizer = new Binarizer(200, 200, 200, 32, 32); imageBinarizer.CreateBinary(sourcePath, destinationPath); string res = imageBinarizer.GetBinary(sourcePath); }
public void BinarizerWithTargetSizeTest() { Binarizer bizer = new Binarizer(targetHeight: 256, targetWidth: 256); foreach (var item in new string[] { "face.jpg", "daenet.png", "gab.png" }) { string trainingImagesPath = Path.Combine(Path.Combine(AppContext.BaseDirectory, "ImageBinarization"), "TestImages"); bizer.CreateBinary(Path.Combine(trainingImagesPath, item), $"binary__256x256_{item}.txt"); } }
public void BinarizerTest() { Binarizer bizer = new Binarizer(); foreach (var item in new string[] { "face.jpg", "daenet.png", "gab.png" }) { string trainingImagesPath = Path.Combine(Path.Combine(AppContext.BaseDirectory, "ImageBinarization"), "TestImages"); bizer.CreateBinary(Path.Combine(trainingImagesPath, item), $"binary_{item}.txt"); } }
/// <summary> /// Binarize image to binarizedImage. /// </summary> /// <param name="mnistImage"></param> /// <param name="imageSize"></param> /// <param name="testName"></param> /// <returns></returns> public static string BinarizeImage(string mnistImage, int imageSize, string testName) { string binaryImage; Binarizer imageBinarizer = new Binarizer(200, 200, 200, imageSize, imageSize); binaryImage = $"{testName}.txt"; if (File.Exists(binaryImage)) { File.Delete(binaryImage); } imageBinarizer.CreateBinary(mnistImage, binaryImage); return(binaryImage); }
/// <summary> /// Binarize image to create an binarized image and return the path to that binarized image. /// </summary> /// <param name="mnistImage"> Path to the source mnist image</param> /// <param name="imageSize">Size of the image (image has same width and height)</param> /// <returns>Path to the output binarized image</returns> private static string BinarizeImage(string mnistImage, int imageSize) { string binaryImage; Binarizer binarizer = new Binarizer(200, 200, 200, imageSize, imageSize); binaryImage = $@"Output\{GetFileName(mnistImage)}.txt"; Directory.CreateDirectory($"Output"); if (File.Exists(binaryImage)) { File.Delete(binaryImage); } binarizer.CreateBinary(mnistImage, binaryImage); return(binaryImage); }