Ejemplo n.º 1
0
        /// <summary>
        /// Applies laplacian operator to image
        /// </summary>
        /// <param name="imagePath">input image path</param>
        /// <param name="outputImagePath">output image path.</param>
        public void Apply(string imagePath, string outputImagePath)
        {
            var endResult          = this.Apply(imagePath);
            var endResultRGBMatrix = MatrixUtils.ConvertMatrixToRGBMatrix(endResult);

            MatrixUtils.CreateImageFromMatrixParalleled(endResultRGBMatrix, outputImagePath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Blurs image with gaussian filter
        /// </summary>
        /// <param name="sourceImagePath">source image path</param>
        /// <param name="kernelSize"></param>
        /// <param name="standardDeviation"></param>
        /// <returns>blurred image matrix</returns>
        public IMatrix Apply(string sourceImagePath, int kernelSize = 5,
                             float standardDeviation = 1f)
        {
            var sourceImageFileInfo = new FileInfo(sourceImagePath);

            if (!sourceImageFileInfo.Exists)
            {
                throw new ArgumentException("sourceImagePath does not point to existing image");
            }

            if (!AllowedImageTypes.Contains(sourceImageFileInfo.Extension))
            {
                throw new ArgumentException("sourceImagePath is not with supported extension. Supported extensions: " +
                                            string.Join(", ", AllowedImageTypes));
            }

            var     image  = MatrixUtils.CreateMatrixFromImage(sourceImagePath);
            IMatrix kernel = null;

            try
            {
                kernel = GenerateGaussianKernel(kernelSize, standardDeviation);
            }
            catch (ArgumentOutOfRangeException exception)
            {
                throw new ArgumentOutOfRangeException("Kernel size must be greater than 1 and be odd number",
                                                      exception);
            }

            var convolutedImageMatrix = MatrixUtils.ConvertMatrixToRGBMatrix(image.ConvoluteParalleled(kernel));

            return(convolutedImageMatrix);
        }