public static BitmapImage GaussianBlur(BitmapSource image, float radius)
 {
     GaussianBlurFilter filter = new GaussianBlurFilter(radius);
     using(var kimage = BitmapSourceToKaliko(image))
     {
         if (kimage == null)
             return null;
         var padding = (int)Math.Ceiling(radius);
         kimage.Crop(-padding, padding, (int)image.Width + padding * 2, (int)image.Height + padding * 2);
         kimage.ApplyFilter(filter);
         return KalikoToBitmap(kimage);
     }
 }
        private static void Sharpen(KalikoImage image, float amount, float radius, int threshold)
        {
            var inPixels   = image.IntArray;
            var workPixels = new int[inPixels.Length];
            var outPixels  = new int[inPixels.Length];

            if (radius > 0)
            {
                var kernel = GaussianBlurFilter.CreateKernel(radius);
                GaussianBlurFilter.ConvolveAndTranspose(kernel, inPixels, workPixels, image.Width, image.Height, true, true, false, ConvolveFilter.EdgeMode.Clamp);
                GaussianBlurFilter.ConvolveAndTranspose(kernel, workPixels, outPixels, image.Height, image.Width, true, false, true, ConvolveFilter.EdgeMode.Clamp);
            }

            for (int index = 0; index < inPixels.Length; index++)
            {
                int rgb1 = inPixels[index];
                int r1   = (rgb1 >> 16) & 0xff;
                int g1   = (rgb1 >> 8) & 0xff;
                int b1   = rgb1 & 0xff;

                int rgb2 = outPixels[index];
                int r2   = (rgb2 >> 16) & 0xff;
                int g2   = (rgb2 >> 8) & 0xff;
                int b2   = rgb2 & 0xff;

                if (Math.Abs(r1 - r2) >= threshold)
                {
                    r1 = PixelUtils.Clamp((int)((amount + 1) * (r1 - r2) + r2));
                }
                if (Math.Abs(g1 - g2) >= threshold)
                {
                    g1 = PixelUtils.Clamp((int)((amount + 1) * (g1 - g2) + g2));
                }
                if (Math.Abs(b1 - b2) >= threshold)
                {
                    b1 = PixelUtils.Clamp((int)((amount + 1) * (b1 - b2) + b2));
                }

                inPixels[index] = (int)(rgb1 & 0xff000000) | (r1 << 16) | (g1 << 8) | b1;
            }

            image.IntArray = inPixels;
        }