Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Upsampling in Frequency Domain




1.1  Upsampling using MATLAB built-in function
1.2  Upsampling in 1D
1.3  Upsampling in 2D or image matrix
2.1  Upsampling a 1D signal
2.2  Upsampling a image matrix

In Frequency domain, upsampling means nothing but the padding of zeros at the end of high frequency components on both sides of the signal.

STEPS TO PERFORM:

1.      Read an image
2.      Obtain the ratio to upsample
3.      Perform Fast Fourier Transform
4.      Shift the Low frequency components to the centre and High frequency components outside.
5.      Add zeros on both the sides of the image
6.      Shift the High frequency components to the centre and Low frequency components to the exterior (Inverse of fftshift)
7.      Perform Inverse Fast Fourier Transform
8.      Display the Upsampled Image

MATLAB CODE:

%UPSAMPLING IN FREQUENCY DOMAIN
%1D UPSAMPLING

FS = 100;
t  = 0:(1/FS):1;

A = 10*sin(2*pi*5*t);
figure,plot(t,A);
 



%FOURIER DOMAIN

FT = fft(A);
fq =linspace(-1/FS,1/FS,101);
figure,plot(fq,abs(FT));title('Before FFTSHIFT');


FT_s = fftshift(FT);
figure,plot(fq,abs(FT_s));title('After FFTSHIFT');


pad_zero = padarray(FT_s,[0 50]);

fq =linspace(-1/FS,1/FS,201);
figure,plot(fq,abs(pad_zero));title('After PADDING WITH ZEROS');


%INVERSE FOURIER TRANSFORM
IFT = ifft(ifftshift(pad_zero));

%UPSAMPLED SIGNAL
t1 = linspace(0,1,201);
figure,plot(t1,(IFT*2),'r',t,A,'g');




EXPLANATION:

Amplitude of the input original signal is 10 and the frequency is 5.
Similarly, the amplitude of the upsampled signal is 10 and the frequency is 5. The number of samples used to plot the signal is increased in the later case.



IMAGE UPSAMPLING IN FOURIER DOMAIN

MATLAB CODE:

%READ AN INPUT IMAGE
A = imread('cameraman.tif');

%RATIO
RatioM = 3;
RatioN = 2;

%UPSAMPLING OVER EACH ROW

mnrow = round(size(A,2)*(RatioM-1)/2);
% 1D FFT ON EACH ROW
row_fft = fft(A,[],2);

%PAD WITH ZEROS ON BOTH SIDES OF EACH ROW
pad_row = padarray(fftshift(row_fft,2),[0 mnrow]);

 
Logarthmic scale
%UPSAMPLING OVER EACH COLUMN
mncol = round(size(A,1)*(RatioN-1)/2);

% 1D FFT ON EACH COLUMN
col_fft = fft(pad_row,[],1);

%PAD WITH ZEROS ON BOTH SIDES OF EACH COLUMN
pad_col = padarray(fftshift(col_fft,1),[mncol 0]);
 
Logarthmic scale
%PERFORM 1D IFFT ON EACH COLUMN
ifft_col = ifft(ifftshift(pad_col,1),[],1);

%PERFORM 1D IFFT ON EACH ROW
ifft_col_row = ifft(ifftshift(ifft_col,2),[],2);

%DISPLAY THE IMAGE AFTER UPSAMPLING
res = abs(ifft_col_row);
res = uint8(res*(numel(res)/numel(A)));


figure,imagesc(res);




SIMPLE VERSION :

A = imread('cameraman.tif');

%RATIO
RatioM = 3;
RatioN = 2;



mnrow = round(size(A,2)*(RatioM-1)/2);
mncol = round(size(A,1)*(RatioN-1)/2);

%FFT ON 2D MATRIX
FT = fftshift(fft2(A));


%PADDING WITH ZEROS
pad_rc = padarray(FT,[mncol mnrow]);


%INVERSE FOURIER TRANSFORM
IFT = ifft2(ifftshift(pad_rc));

Img = uint8(abs(IFT)*(numel(IFT)/numel(A)));
figure,imagesc(Img);




like button Like "IMAGE PROCESSING" page
Previous Post Next Post Home
Google ping Hypersmash.com