# Sharpening an image using emgu

I have c# desktop application and I am using emgu framework as a wrapper for OpenCV.

I am trying to sharpen an image because the input images are not great.

I tired a technique I found via searches that suggest from the original image:

I take a copy and blur it. I then take another copy of the original and invert it.
I then merge the 2 new images together.
I then finally invert that merged image.

I have done all that but the image pretty much looks the same.

Is this the right approach?

I can post my code if need be - I used Aforge to quickly test this approach though.

UPDATE: To answer my own question I used this:

            Image<Bgr, byte> image = new Image<Bgr, byte>(@"D:\20140320022038047.jpg");
Image<Bgr, byte> image2 = new Image<Bgr, byte>(@"D:\20140320022038047.jpg");
Emgu.CV.CvInvoke.cvSmooth(image, image2, SMOOTH_TYPE.CV_GAUSSIAN, 5, 5, 9, 9);
Emgu.CV.CvInvoke.cvAddWeighted(image, 1.5, image2, -0.5, 0, image);


## 1 Answer

I know this answer is very late but I think this question worth an answer

The algorithm you used goes as follows:

1. Blur the original image using the Gaussian filter with given Mask Size & Sigma

2. Subtract the blurred image from the original (result is called Mask) to eliminate background and get the edges regions

3. Add a weighted portion from the mask to the original image by multiplying the Mask (the edges only) by K to enhance edges regions

K: User input (If K = 1 Unsharp, If K > 1 Highboost)

Mask(x,y) = Orig(x,y) – Blurred(x,y)

Result(x,y) = Orig(x,y) + K × Mask(x,y)

Here is the code:

public static Image<Gray, byte> Sharpen(Image<Gray, byte> image, int w, int h, double sigma1, double sigma2, int k)
{
w = (w % 2 == 0) ? w - 1 : w;
h = (h % 2 == 0) ? h - 1 : h;
//apply gaussian smoothing using w, h and sigma
var gaussianSmooth = image.SmoothGaussian(w, h, sigma1, sigma2);
//obtain the mask by subtracting the gaussian smoothed image from the original one
var mask = image - gaussianSmooth;
//add a weighted value k to the obtained mask
mask *= k;
//sum with the original image
image += mask;
return image;
}


I think your problem is that you didn't subtract the smoothed image from the original image, anyway I hope this help

• worth giving a go. Which I will as soon as I get time this evening. Thanks :) – Andrew Simpson Feb 3 '15 at 16:27