private static void testBlending(string filePath1, string filePath2, string outputPath) { ImageBlender blender = new SimpleGrayscaleImageBlender(); List <ImageDescription> images = new List <ImageDescription>(); images.Add(ImageFileHandler.loadFromPath(filePath1)); images.Add(ImageFileHandler.loadFromPath(filePath2)); ImageDescription result = blender.blendImages(images); ImageFileHandler.saveToPath(result, outputPath, ".png"); }
private static void testAlgorithmOnFile(string algorithmToTest, string filename) { Console.WriteLine("Started loading " + algorithmToTest); EdgeDetectionAlgorithm edgeDetectionAlgorithm = EdgeDetectionAlgorithmUtil.loadAlgorithmFromCompressedFile(algorithmToTest); Console.WriteLine("Loaded algorithm. Testing."); ImageDescription inputImage = ImageFileHandler.loadFromPath(filename); ImageDescription outputImage = edgeDetectionAlgorithm.test(inputImage); ImageFileHandler.saveToPath(outputImage, "test", ".png"); Console.WriteLine("Saved"); }
private static void testFiltering(string filePath, string outputPath) { ImageDescription inputImage = ImageFileHandler.loadFromPath(filePath); //ImageFilter filter = new CannyAppenderFilter(); //ImageFilter filter = new KirschAppenderFilter(); ImageFilter filter = new SobelAppenderFilter(); ImageDescription outputImage = filter.filter(inputImage); GaussFilter gaussFilter = new GaussFilter(5, 1.4f, new HashSet <ColorChannelEnum> { ColorChannelEnum.Red, ColorChannelEnum.Green, ColorChannelEnum.Blue }); outputImage = gaussFilter.filter(outputImage); ImageFileHandler.saveToPath(outputImage, outputPath, ".png"); //ImageDescription newOutputImage = new ImageDescription(); //newOutputImage.sizeX = outputImage.sizeX; //newOutputImage.sizeY = outputImage.sizeY; //newOutputImage.grayscale = true; //newOutputImage.setColorChannel(ColorChannelEnum.Gray, outputImage.getColorChannel(ColorChannelEnum.Canny)); //ImageFileHandler.saveToPath(newOutputImage, "test2", ".png"); }
public void testNestedAlgorithm(ContextualMemoryNestedAlgorithm nestedAlgorithm) { DateTime testingStart = DateTime.Now; List <String> fileList = benchmark.getTestFilesPathList(); int index = 1; string outputDirectory = null; foreach (string testFileName in fileList) { DateTime start = DateTime.Now; outputDirectory = Path.GetDirectoryName(benchmark.getTestFileOutputPathWithoutExtension(testFileName)); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } Console.WriteLine(index + "/" + fileList.Count + " Testing file: " + Path.GetFileName(testFileName)); ImageDescription inputImage = ImageFileHandler.loadFromPath(testFileName); List <ContextualMemoryNestedAlgorithmLayer> layers = nestedAlgorithm.getLayers(); List <ImageDescription> computedImages = nestedAlgorithm.computeImageForLayers(inputImage, layers.Count); for (int i = 0; i < layers.Count; i++) { if (layers[i].outputResults) { ImageFileHandler.saveToPath(computedImages[i], benchmark.getTestFileOutputPathWithoutExtension(testFileName) + "_layer" + i, outputFileExtension); } } ImageDescription outputImage = nestedAlgorithm.getImageBlender().blendImages(computedImages); ImageFileHandler.saveToPath(outputImage, benchmark.getTestFileOutputPathWithoutExtension(testFileName), outputFileExtension); double timeElapsed = (DateTime.Now - start).TotalSeconds; double timeElapsedSoFar = (DateTime.Now - testingStart).TotalSeconds; double estimatedTime = (timeElapsedSoFar / index) * (fileList.Count - index); Console.WriteLine(timeElapsed.ToString("0.00") + "s Time elapsed: " + timeElapsedSoFar.ToString("0.00") + "s ETA: " + estimatedTime.ToString("0.00") + "s"); index++; } double totalTimeElapsed = (DateTime.Now - testingStart).TotalSeconds; Console.WriteLine("Testing took " + totalTimeElapsed.ToString("0.00") + " sec."); if (testOnTrainingFiles) { Console.WriteLine("Testing on training files"); testingStart = DateTime.Now; index = 0; // we have the outputDirectory from test, else, relative to the exe outputDirectory = Path.Combine(outputDirectory, trainingFilesTestOutput); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } fileList = new List <string>(benchmark.getTrainingFilesPathList()); foreach (string trainingFileName in fileList) { DateTime start = DateTime.Now; string outputPath = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(trainingFileName)); Console.WriteLine((index + 1) + "/" + fileList.Count + " Testing file: " + Path.GetFileName(trainingFileName)); ImageDescription inputImage = ImageFileHandler.loadFromPath(trainingFileName); List <ContextualMemoryNestedAlgorithmLayer> layers = nestedAlgorithm.getLayers(); List <ImageDescription> computedImages = nestedAlgorithm.computeImageForLayers(inputImage, layers.Count); for (int i = 0; i < layers.Count; i++) { if (layers[i].outputResults) { ImageFileHandler.saveToPath(computedImages[i], outputPath + "_layer" + i, outputFileExtension); } } ImageDescription outputImage = nestedAlgorithm.getImageBlender().blendImages(computedImages); ImageFileHandler.saveToPath(outputImage, outputPath, outputFileExtension); index++; double timeElapsed = (DateTime.Now - start).TotalSeconds; Console.WriteLine(timeElapsed.ToString("0.00") + " seconds"); } totalTimeElapsed = (DateTime.Now - testingStart).TotalSeconds; Console.WriteLine("Testing on training files took " + totalTimeElapsed.ToString("0.00") + " sec."); } }
public void test(EdgeDetectionAlgorithm algorithm) { DateTime testingStart = DateTime.Now; List <String> fileList = benchmark.getTestFilesPathList(); int index = 1; string outputDirectory = null; foreach (string testFileName in fileList) { DateTime start = DateTime.Now; outputDirectory = Path.GetDirectoryName(benchmark.getTestFileOutputPathWithoutExtension(testFileName)); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } Console.WriteLine(index + "/" + fileList.Count + " Testing file: " + Path.GetFileName(testFileName)); ImageDescription inputImage = ImageFileHandler.loadFromPath(testFileName); ImageDescription outputImage = algorithm.test(inputImage); ImageFileHandler.saveToPath(outputImage, benchmark.getTestFileOutputPathWithoutExtension(testFileName), outputFileExtension); double timeElapsed = (DateTime.Now - start).TotalSeconds; double timeElapsedSoFar = (DateTime.Now - testingStart).TotalSeconds; double estimatedTime = (timeElapsedSoFar / index) * (fileList.Count - index); Console.WriteLine(timeElapsed.ToString("0.00") + "s Time elapsed: " + timeElapsedSoFar.ToString("0.00") + "s ETA: " + estimatedTime.ToString("0.00") + "s"); index++; } double totalTimeElapsed = (DateTime.Now - testingStart).TotalSeconds; Console.WriteLine("Testing took " + totalTimeElapsed.ToString("0.00") + " sec."); if (testOnTrainingFiles) { Console.WriteLine("Testing on training files"); testingStart = DateTime.Now; index = 0; // we have the outputDirectory from test, else, relative to the exe outputDirectory = Path.Combine(outputDirectory, trainingFilesTestOutput); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } fileList = new List <string>(benchmark.getTrainingFilesPathList()); foreach (string trainingFileName in fileList) { DateTime start = DateTime.Now; string outputPath = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(trainingFileName)); Console.WriteLine(index + "/" + fileList.Count + " Testing file: " + Path.GetFileName(trainingFileName)); ImageDescription inputImage = ImageFileHandler.loadFromPath(trainingFileName); ImageDescription outputImage = algorithm.test(inputImage); ImageFileHandler.saveToPath(outputImage, outputPath, outputFileExtension); index++; double timeElapsed = (DateTime.Now - start).TotalSeconds; Console.WriteLine(timeElapsed.ToString("0.00") + " seconds"); } totalTimeElapsed = (DateTime.Now - testingStart).TotalSeconds; Console.WriteLine("Testing on training files took " + totalTimeElapsed.ToString("0.00") + " sec."); } }