title: Creating a high pass filter in matlab
body: <p>I'm trying to create a high pass filter in Matlab. I generate the Gaussian Kernel using</p>
  
  <pre><code>function kernel = compute_kernel(sigma,size)
  [x,y] = meshgrid(-size/2:size/2,-size/2:size/2);
  constant = 1/(2*pi*sigma*sigma);
  kernel = constant*exp( -(y.^2 + x.^2 )/(2 * sigma * sigma));
  kernel = (kernel - min(kernel(:)))./(max(kernel(:)) - min(kernel(:)));
  end
  </code></pre>
  
  <p>Then after creating the Kernel I use it to create a low pass filter for the image(variable <code>im2</code> ):</p>
  
  <pre><code>g = compute_kernel(9,101);
  im2_low = conv2(im2,g,'same');
  </code></pre>
  
  <p>As I understand I can then use subtract the filtered image from the original image(in the frequency domain) to extract the high frequencies making it the equivalent of a high pass filter.</p>
  
  <pre><code>F = fft2(im2_low);
  IM2 = fft2(im2);
  IM2_high = IM2 - F;
  
  figure; fftshow(IM2_high);
  im2_high = ifft2(IM2_high);
  figure; imshow(im2_high,[]);
  </code></pre>
  
  <p>There seems to be something wrong with this though. When I view the high pass filtered image it seems to a color inverted blurred image not the ones with the edges defined as I've seen online. I'm not sure if my process is wrong or whether I'm just using the wrong values for my Gaussian Kernel.</p>