public override ImgProps Process(ImgProps input) { ImgProps noisedImage = new ImgProps(input.Width, input.Height); Random random = new Random(); const int highestByte = 255; int noisedData; for (int i = 0; i < input.Width; i++) { for (int j = 0; j < input.Height; j++) { noisedData = random.Next(-(int)(_decimalPercent * highestByte), +(int)(_decimalPercent * highestByte)); noisedImage[i, j] = new Rgba32( ImageUtility.RestrictOverflow(input[i, j].R + noisedData), ImageUtility.RestrictOverflow(input[i, j].G + noisedData), ImageUtility.RestrictOverflow(input[i, j].B + noisedData), input[i, j].A ); } } return(noisedImage); }
public override ImgProps Process(ImgProps input) { if (_kernelType == "edge") { selectedKernel = ImageUtility.edge; } else if (_kernelType == "sharpen") { selectedKernel = ImageUtility.sharpen; } else if (_kernelType == "blur") { selectedKernel = ImageUtility.blur; } int imageWidth = input.Width; int imageheight = input.Height; int kernelWidth = selectedKernel.GetLength(0); int kernelHeight = selectedKernel.GetLength(1); int offset = (kernelWidth - 1) / 2; ImgProps convolved = new ImgProps(imageWidth - offset, imageheight - offset); for (int i = offset; i < input.Width - offset; i++) { for (int j = offset; j < input.Height - offset; j++) { double red = 0; double green = 0; double blue = 0; for (int a = 0; a < kernelWidth; a++) { for (int b = 0; b < kernelHeight; b++) { red += input[i + a - (offset), j + b - (offset)].R * selectedKernel[a, b]; green += input[i + a - (offset), j + b - (offset)].G * selectedKernel[a, b]; blue += input[i + a - (offset), j + b - (offset)].B * selectedKernel[a, b]; } } red = ImageUtility.RestrictOverflow((int)red); green = ImageUtility.RestrictOverflow((int)green); blue = ImageUtility.RestrictOverflow((int)blue); convolved[i, j] = new Rgba32((byte)red, (byte)green, (byte)blue); } } return(convolved); }
public ImgProps GetOutput(ImgProps input, string saveDir = "", bool logging = false, bool isSaveAll = false) { //Insert output of a node as input to its connected node if (prevNode != null) { try { input = prevNode.GetOutput(input, saveDir, logging, isSaveAll); } catch (StackOverflowException) { Console.WriteLine("Stack limit reached - pipeline is too long"); return(null); } imgNum++; } //Measure the processing time watch.Start(); ImgProps output = Process(input); watch.Stop(); if (isSaveAll == true) { //save all the intermidiate and final nodes using counter as name output.Write(saveDir + "/" + imgNum.ToString()); } if (logging == true) { //Log data corresponding to processed node Console.WriteLine("Node name: " + NodeName); Console.WriteLine("Processing time: {0}ms", watch.ElapsedMilliseconds); Console.WriteLine("Size of input image: " + input.ToString()); Console.WriteLine("Size of output image: " + output.ToString() + "\n"); } return(output); }
public override ImgProps Process(ImgProps input) { double centerX = input.Width / 2; double centerY = input.Height / 2; double maxDistance = Math.Sqrt(Math.Pow(centerX, 2) + Math.Pow(centerY, 2)); double distX; double distY; double distance; double brightness; ImgProps vignetteImage = new ImgProps(input.Width, input.Height); for (int i = 0; i < input.Width; i++) { for (int j = 0; j < input.Height; j++) { distX = centerX - i; distY = centerY - j; distance = (int)(Math.Sqrt(Math.Pow(distX, 2) + Math.Pow(distY, 2))); brightness = Math.Pow(((maxDistance - distance) / maxDistance), 2); vignetteImage[i, j] = new Rgba32( ImageUtility.RestrictOverflow((int)(input[i, j].R * brightness)), ImageUtility.RestrictOverflow((int)(input[i, j].G * brightness)), ImageUtility.RestrictOverflow((int)(input[i, j].B * brightness)), input[i, j].A ); } } return(vignetteImage); }
//Create an abstract methods for nodes to inherit from this base class public abstract ImgProps Process(ImgProps input);
//private public static void Process() { if (!Directory.Exists(_outputDir)) { Directory.CreateDirectory(_outputDir); } BaseNode endNode = ParsePipeLine(); if (endNode == null) { Console.WriteLine("EndNode is null. Failed"); return; } if (Directory.Exists(_imgInput)) { int counter = 0; string[] filePaths; filePaths = Directory.GetFiles(_imgInput); for (int i = 0; i < filePaths.Length; i++) { counter++; try { img = new ImgProps(filePaths[i]); } catch (FileNotFoundException) { Console.WriteLine("Directory not found"); return; } ImgProps outputImg = endNode.GetOutput(img, _outputDir, _isVerbose, _isSaveAll); if (outputImg == null) { Console.WriteLine("Pipeline failed"); return; } BaseNode.imgNum++; if (_isSaveAll == false) { outputImg.Write(_outputDir + "/final"); } } } else { try { img = new ImgProps(_imgInput); } catch (FileNotFoundException) { Console.WriteLine("File not found"); return; } ImgProps outputImg = endNode.GetOutput(img, _outputDir, _isVerbose, _isSaveAll); if (outputImg == null) { Console.WriteLine("Pipeline failed"); return; } if (_isSaveAll == false) { outputImg.Write(_outputDir + "/final"); } } }