title: Removing periodic noise from an image using the Fourier Transform
body: <p>I am performing the 2D FFT on a particular image and I get its spectral components. Now this image has been superimposed with another image to create periodic noise. </p>
  
  <p>The original image as well as the periodic noise version is shown below:</p>
  
  <h1>Original Image</h1>
  
  <p><a href="https://i.stack.imgur.com/e9gla.png" rel="noreferrer"><img src="https://i.stack.imgur.com/e9gla.png" alt="enter image description here"></a></p>
  
  <h1>Periodic Noise Image</h1>
  
  <p><a href="https://i.stack.imgur.com/oIumJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/oIumJ.png" alt="enter image description here"></a></p>
  
  <p>To filter this out, I used manual boxes that masked the components in the magnitude spectrum that are quite large relative to the other components as shown below.  </p>
  
  <p><a href="https://i.stack.imgur.com/KnUI5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KnUI5.png" alt="enter image description here"></a></p>
  
  <p>After this is done, I perform an inverse FFT, but I do not get the original image back. </p>
  
  <p><a href="https://i.stack.imgur.com/mr0zE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mr0zE.png" alt="enter image description here"></a></p>
  
  <p>Does anyone know what I'm doing wrong?</p>
  
  <p>Here is the code that masks the values and then proceeds to do an inverse 2D FFT on the masked spectral image: </p>
  
  <pre><code>pat1 = imread('Pattern1.png');
  
  spec_orig = fft2(double(pat1));     
  spec_orig2 = abs(spec_orig); 
  spec_img = fftshift(spec_orig2);
  
  for j = 115:125
      for n = 96:106
          spec_img(n,j) = 0; 
      end
      for n = 216:226
          spec_img(n,j) = 0; 
      end
      for n = 274:284
          spec_img(n,j) = 0; 
      end
      for n = 298:308
          spec_img(n,j) = 0; 
      end
      for n = 12:22
          spec_img(n,j) = 0; 
      end
      for n = 37:47
          spec_img(n,j) = 0; 
      end
  end
  
  %Getting Back the Image for Pattern1
  figure;subplot(2,1,1);
  spec_img = log(1 + spec_img);
  imshow(spec_img,[]); 
  
  subplot(2,1,2);
  ptnfx = ifft2(spec_img);
  imshow(ptnfx);
  </code></pre>