1
votes

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 matrix minus the low-pass filter, so I did the following:

image= imread('Question3_Data-Cats.jpg'); % read image

H = 1 - fspecial('gaussian' ,[5 5],2); % create unsharp mask
sharpened = imfilter(image,H);  % create a sharpened version of the image using that mask

imshow([image sharpened]); %showing input & output images

I did not get a sharpened image. Instead, I got a white image with some colors on a small region of the image. Can someone help? Thank you.

3
You're not subtracting the identity matrix, you're subtracting a matrix of ones.Roger Rowland
I tried H = 255-fspecial('gaussian' ,[5 5],2); It did not work as well.Traveling Salesman
Have you tried eye()?Roger Rowland
yup...it did not work as wellTraveling Salesman

3 Answers

6
votes

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 f - f \ast g. 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.

image detail

After you have extracted the image details from the image, you have to add them back to the image to get a sharpened image.

Sharpen 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)

control brightness of image details

5
votes

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.

-1
votes
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