FFT Combination of Two Images

9 views (last 30 days)
John Smith
John Smith on 2 Jul 2015
Commented: John Smith on 6 Jul 2015
I am trying to take two simple images (a horizontal slit and a vertical slit), take the fft2 of each individual image, combine the fft2 version of the two images using some sort of operation to make a single fft2 image, then take the ifft2 of that combined image to get a new original image of the horizontal and vertical slits combined. I am stuck on the combining operation. I've tried 'or' and 'bitor' but it's not quite working. The ifft2 does not result in the correct image. Someone please help!
Here is my attempt at the code:
horz = zeros(16, 16);
horz(:, 8-2:8+2) = 255.;
vert = zeros(16, 16);
vert(8-2:8+2, :) = 255.;
f_horz = fft2(horz);
f_horzshift = fftshift(f_horz);
f_vert = fft2(vert);
f_vertshift = fftshift(f_vert);
bitorop = bitor(f_horzshift, f_vertshift);
inverse = ifft2(bitorop);
surf (abs(inverse))
  2 Comments
Geoff Hayes
Geoff Hayes on 3 Jul 2015
John - when I run your above code, I observe the following error
Error using bitor
Inputs must be real.
which makes sense since your f_horzshift and f_vertshift involve complex numbers.
Since the Fourier transform is linear, then why not just add the two
inverse = ifft2(f_horzshift + f_vertshift);
Why choose bit operations over the above? And what is the correct image?
John Smith
John Smith on 4 Jul 2015
I tried a simple addition of the two fourier versions, but where the two intersect in the middle, there is twice the intensity, since they are adding. I need everything to be at one level, if that makes sense. Is there a way to change a specific coordinate in MatLab? The only reason I was trying 'or' or 'bitor' was to avoid this intensity spike at the point of intersection.
I know it would be easier to just start off with an image of the two already combined, but I need to know how to do it in this 'roundabout fourier' fashion for a fourier filtering project that I am working on.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 3 Jul 2015
No, you don't do that at all. That would not make any physical sense. What are you trying to do anyway? Do you want the FT of the product of the vertical slit and a horizontal slit? If so, you know that multiplication in one domain is convolution in the other domain, not anything with bit processing.
  5 Comments
Image Analyst
Image Analyst on 4 Jul 2015
You can set a matrix value with indexing and assignment
yourMatrix(row, column) = newValue;
But I don't know why you're adding two spectra. And then why you're changing some of the values like that. It doesn't seem to be what you should be doing in Fourier filtering. Maybe you can explain the theoretical basis for this kind of filtering.
John Smith
John Smith on 6 Jul 2015
I guess I wouldn't call what I'm doing right now particularly filtering, I just need to get familiar with the fft/ifft process on MatLab. I added the two spectra and tried to change that value, but it is still showing a spike in the middle where the two added at that point of intersection. Here's the code so you can see what's happening. As you can see, when I take the inverse, I get the image I want, except the spike that's in the middle. Any tips on how to get rid of that middle value (255,255) that's spiking? Thanks so much.
horz= zeros(512, 512);
horz(:, 256-4:256+4) = 255.;
vert = zeros(512, 512);
vert(256-8:256+8, :) = 255.;
f_horz = fft2(horz);
f_horzshift = fftshift(f_horz);
f_vert = fft2(vert);
f_vertshift = fftshift(f_vert);
addop = f_horzshift + f_vertshift;
addop(255,255) = 0;
surf (abs(addop))
inv = ifft2(addop);
surf (abs(inv))

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!