I am trying to sharpen an image by designing a Gaussian High-Pass Filter. I would like to do this using the fact that the high-pass filter is equivalent to the identity matr
Try this:
H = padarray(2,[2 2]) - fspecial('gaussian' ,[5 5],2); % create unsharp mask
1 is a scalar. You need a 5x5 array with one in the center. Furthermore, the filter elements must sum to one if you want to conserve brightness, so you need to double the central value to counter the amount you are subtracting.
I= imread('peppers.png'); % read image
H = padarray(2,[2 2]) - fspecial('gaussian' ,[5 5],2); % create unsharp mask % create unsharp mask
figure,imshow(I);
K = imfilter(I,H); % create a sharpened version of the image using that mask
figure,imshow(K); %showing input & output images
Let g
be the gaussian
kernel and f
be the image. Then f * g
(convolution) gives the blurred version of the image. That means low-passed
version of the image.
Then consider . It means image - lowpass image
. That gives the high-passed
version of the image. It contains only image details. The details are in white on the black background. I think that is the image you are getting right now.
After you have extracted the image details from the image, you have to add them back to the image to get a sharpened image.
That means you can get the sharpened image by convolution of 2e - g
with your image(This is the unsharp mask).
You can get 2e
from matlab using padarray(2,[2 2])
and g
using fspecial('gaussian' ,[5 5],2)
.
H = padarray(2,[2 2]) - fspecial('gaussian' ,[5 5],2); %create unsharp mask
Sometimes, you will need to control the brightness of the image details. You can do that by
sharpen image = image + alpha(image details)