0

I am trying to apply high pass filter to this image.

A = 'url';
B = imread(A, 'jpg');
figure(1), imshow(B);
C = rgb2gray(B);
figure(2), imshow(C);
e = fspecial('gaussian', [3,3], 0.5);
n = imfilter(C,e);
figure(3), imshow(n)
p = [1 1 1;
     1 1 1;
     1 1 1]/9;
figure(4), freqz2(p)
D = imfilter(C,p);
figure(5), imshow(D)
K = medfilt2(D,[3 3]);
figure(6), imshow(K)

I am applying a low pass filter here. How can I apply a high pass filter?

m7913d
  • 10,244
  • 7
  • 28
  • 56
Tuba
  • 11
  • 1
  • 1
  • A 3x3 filter is never a Gausian. I don't know why MATLAB allows this. A sigma of 0.5 is too small to properly sample the Gaussian kernel. You want to keep the sigma parameter to at least 0.8, but preferably 1, and the filter size to 6*sigma+1 (so at least 7x7). If you do anything else, you might as well use a triangular filter, as you won't have any of the advantages of the Gaussian kernel. – Cris Luengo Mar 14 '17 at 00:52
  • __Reopen:__ This problem is about 2D (image) filtering, while the other is about 1D (signal) filtering. One could not simply apply a 1D method to 2D data. – m7913d May 25 '17 at 09:46

2 Answers2

0

try using a different filter, like:

h = fspecial('laplacian');
user2999345
  • 4,195
  • 1
  • 13
  • 20
0

There exist multiple high-pass filters that you can use depending on your specific application. High pass filters are typically used to highlight boundaries.

An often used function is the Laplacian of Gaussian filter:

log = fspecial('log',[3 3],0.5);
figure; freqz2(log);

Another one is the Laplacian filter:

laplacian = fspecial('laplacian',0.5);
figure; freqz2(laplacian);

Or you can define your own filter, for example a first order derivative 2D filter:

p = [1 0 -1;
     0 0 0;
    -1 0 1];
figure; freqz2(p)
m7913d
  • 10,244
  • 7
  • 28
  • 56
  • 1
    Just wanted to point out that the [Laplacian filter](https://www.mathworks.com/help/images/ref/fspecial.html#d123e83709) with fspecial takes in just one parameter alpha (<1) and always returns a 3x3 filter. Don't know if you wrote [3,3] just for understanding but nevertheless, thought I will point it out – Abhishek Tyagi Mar 11 '21 at 14:25
  • @AbhishekTyagi thanks, I corrected my answer. – m7913d Mar 11 '21 at 16:59