Removing Periodic Noise from Images with MATLAB

It can happen that an electromagnetic field disturbs the images of cameras on microscopes with a periodic noise. While the specialists are looking for the source of the interference, I quickly wrote a MATLAB script to filter the noisy image.

As an example, we use this image taken to quantify charcoal from lake sediment. Unfortunately, it shows periodic noise. I searched the internet for explanations and solutions, found a number of similar examples and a MATLAB solution on Stackoverflow, actually when I almost solved the problem  myself. The only problem was that I forgot to undo the centering of the spectrum and did not take the real part at the end. Answer 1 of the Stackoverflow post solved the problem for me. We first load the image I using

clear, clc, close all

samplename = 'CHB-14-2B-8H-1-B10';
filename = [samplename,'.tif'];
I = imread(filename);


We use a for loop for the three colors. The following script computes an FFT2 of the image, centers the resulting spectrum, manually locates the periodic disturbance, zeros the spectral peaks of the periodic noise, undoes the centering and back transforms and displays the denoised image J.

Y1 = fft2(I);
Y1 = fftshift(Y1);

Y2 = Y1;
Y2(782:788,1025,:) = 0;
Y2(750:756,1025,:) = 0;

Y3 = ifftshift(Y2);
Y3 = ifft2(Y3);
Y3 = real(Y3);

J = uint8(Y3);

We can display, for example, the corrected blue channel of the image using

   'XLim',[980 1070],...
   'YLim',[740 800])
clim([5 20]), colormap jet

We then display the original and denoised image side by side using

nexttile, imshow(I)
nexttile, imshow(J)

We then save the denoised image using

filename = [samplename,'_corrected.tif'];

The result looks pretty good. You can change the indices of the pixels which values are set to zero to improve the result.


Trauth, M.H. (2021) MATLAB Recipes for Earth Sciences – Fifth Edition. Springer International Publishing, 517 p., ISBN 978-3-030-38440-1. (MRES)