Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Removing periodic noise from an image using the Fourier Transform

Date: 2023-01-02 11:25:07

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.

The original image as well as the periodic noise version is shown below: 

Original Image 

Periodic Noise Image 

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. 

After this is done, I perform an inverse FFT, but I do not get the original image back. 

Does anyone know what I'm doing wrong?

Here is the code that masks the values and then proceeds to do an inverse 2D FFT on the masked spectral image: 

 

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

Expert Answer:

Filtering in the frequency domain is a tricky business to get right. Your code has a few errors that are preventing you from reconstructing the original image:

  1. You are applying the filtering on the magnitude component only. You have to do this on the original image spectrum, not just the magnitude component. The phase is essential for proper reconstruction. BTW, to coin a signal processing term, what you are implementing is a notch filter or a band-stop filter, which removes certain select frequencies.

  2. You centered the spectrum via fftshift but after you filtered you forgot to undo the shift. You must invoke ifftshift on your resulting filtered image to undo the centering.

  3. You're finding the inverse FFT of the log-transformed image. Remember that performing a log transform of the spectrum is only for display purposes. You do not use this when filtering or finding the inverse. Doing this will give you unintended consequences as the majority of the spectrum has been changed due to a non-linear operation. You have to do it on the original image spectrum itself.

  4. A minor note, but make sure you call real after you filter the result after you take the inverse FFT. There are most likely some residual imaginary components that are due to computational floating-point errors and so calling real will only extract the real components of the signal.

With these corrections, this is the code I have. I've read your image directly from matlabhelpers to be reproducible: 

 

pat1 = imread('http://i.stack.imgur.com/oIumJ.png');

%// Change
spec_orig = fft2(double(pat1)); 
spec_img = fftshift(spec_orig);

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

%// Change
ptnfx = real(ifft2(ifftshift(spec_img)));
imshow(ptnfx,[]);

I get this image: 

A pretty good reconstruction of the original image I'll add. You'll still see a bit of streaking and that is highly dependent on the notch filter shape and size. Perhaps make the size bigger and even more so, make the shape of the notch filter circular instead of square. This has a tendency to preserve more of the original image as hard edges introduced by the corners of the squares have unintended ringing effects. 

 

Why Matlabhelpers ?

Looking for reliable MATLAB assignment help? Our expert MATLAB tutors deliver high-quality, easy-to-understand solutions tailored to your academic needs. Whether you're studying at Monash University, the University of Sydney, UNSW, or the University of Melbourne, we provide trusted MATLAB assistance to help you excel. Contact us today for the best MATLAB solutions online and achieve academic success!

MATLAB Assignment Help Services

Personalized Tutoring: Get one-on-one guidance from our MATLAB experts. Whether you're tackling basic concepts or advanced algorithms, we provide clear, step-by-step explanations to help you master MATLAB with confidence.

Assignment Assistance: Struggling with tight deadlines or complex assignments? Our team offers end-to-end support, from problem analysis to code development and debugging, ensuring your assignments meet the highest academic standards.

Project Development: Need expert help with your MATLAB research project? We assist in designing and implementing robust solutions, covering project planning, data collection, coding, simulation, and result analysis.

Coursework Support: Enhance your understanding of MATLAB with our comprehensive coursework assistance. We help you grasp lecture concepts, complete lab exercises, and prepare effectively for exams.

Thesis and Dissertation Guidance: Incorporate MATLAB seamlessly into your thesis or dissertation. Our experts provide support for data analysis, modeling, and simulation, ensuring your research is methodologically sound and impactful.

Contact us on WhatsApp for MATLAB help

Contact us on Telegram for MATLAB solutions