Nasim
Nasim

Reputation: 169

Zero pad image before FFT in MATLAB

I have an image of size 64x64 and I should take its Fourier transform. I should pad with zeros to the right and bottom of the original image to make it 128x128, and then again take its Fourier transform. And then repeat this procedure for 256x256 and 512x512 sized images and find a relation between the final Fourier transforms.

Can anyone tell me how should I do this? I don't know how to zero pad the image to get a double sized image with half zeros.

Upvotes: 1

Views: 834

Answers (1)

rinkert
rinkert

Reputation: 6863

There are multiple ways to zero pad. You can just create an array using zeros of double the size, and then put in the image in the indices on the top left:

A = imread('coins.png');

[s1, s2] = size(A);
B = zeros(s1*2, s2*2, class(A));
B(1:s1,1:s2) = A;

To make sure that the new array B is of the same type as the original image A, I used class(A).

Alternatively you can use padarray. Specify the number of elements to pad in each direction, what to pad, and where to put it ('post').

C = padarray(A, [s1 s2], 0, 'post');

Upvotes: 1

Related Questions