Filtering in the frequency domain

25 views (last 30 days)
Hello everyone,
I am just getting into matlab and and working through some projects for digitam image processing. I wrote some matlab code to filter in the frequency domain but when I plot my image at multiple points I am getting issues from the expected results. I believe the issues are plotting and data type related and wanted to get some feedback on how to do things better.
I need to accomplish the following:
  1. Given an input f(x,y) of size M x N obtain the padding sizes P and Q. P = 2M, Q = 2N.
  2. Form a padded image fp(x,y) of size P x Q using zero padding.
  3. Center the image using fp(x,y) * (-1)^(x+y)
  4. Compute the DFT F(u,v) of the image from step 3.
  5. Construct a real symmetric filter transfer function H(u,v) of size P x Q with center at (P/2, Q/2).
  6. Form the product G(u,v)=G(u,v)*H(u,v) using element wise multiplication.
  7. Obtain the filtered image by computing the IDFT of G(u,v), and decenter the image. gp(x,y) = (real[IDFT{G(u,v)}])*(-1)^(x+y)
  8. Obtain the final filtered result g(x,y) of the same size as the input image by extracting the M x N region from the top, left quadrant of gp(x,y).
I have written the following code to filter my image and accomplish the steps above (thanks to lots of helpful answers on this website).
Question:
In my figure F_uv_dftImage I should see a periodic frequency spectrum. I can but I need to zoom in really close currently to see a tiny image. In the book im using they show this a lot more clearly. Am I using the wrong data types throughout my code (double) to get the results? Or am I just plotting these graphs in the wrong way to display the data? Any input would be great!
If you want to see my code please just message me directly.
  1 Comment
Uzair Muhammad
Uzair Muhammad on 31 Mar 2020
can you please share the code. thanks in advance
Email : uzairali398@gmail.com

Sign in to comment.

Accepted Answer

Aleksander Banbur
Aleksander Banbur on 28 Sep 2019
I solved my problem. In order to plot the DFT properly you need to scale it logarithmically. You can use the log transformation which is s = c*log(1+r) where r is the input DFT image normalized (r=DFT_Image/255), c is a constant, and s is your new log scaled image which you can plot. This fixed all my issues.

More Answers (1)

alo halo
alo halo on 15 Dec 2019
I cannot find the direct message option. Can you please share your code with me?

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!