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 ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

Our Comprehensive Matlab Assignment Help Services

Personalized Tutoring:Our team of MATLAB experts offers one-on-one tutoring sessions tailored to your specific needs. Whether you’re struggling with basic concepts or advanced algorithms, we provide clear, step-by-step guidance to help you understand and master MATLAB.

Assignment Assistance:Facing tight deadlines or complex assignments? We’re here to help! From initial problem analysis to code development and debugging, we offer full-spectrum support to ensure your assignments meet the highest standards.

Project Development: Need help with a research project? Our specialists can assist you in designing and implementing robust MATLAB solutions. We cover everything from project planning and data collection to coding, simulation, and result analysis.

Coursework Support: We provide comprehensive support for your coursework, helping you understand lectures, complete lab exercises, and prepare for exams. Our goal is to ensure you grasp the core principles and practical applications of MATLAB.

Thesis and Dissertation Guidance:Writing a thesis or dissertation? Our experts can assist you in incorporating MATLAB for data analysis, modeling, and simulation. We help you develop a strong methodological framework and ensure your research stands out.

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com