# IMAGE PROCESSING

" 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:

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');

fq =linspace(-1/FS,1/FS,201);

%INVERSE FOURIER TRANSFORM

%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:

%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

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

% 1D FFT ON EACH COLUMN

%PAD WITH ZEROS ON BOTH SIDES OF EACH COLUMN

 Logarthmic scale
%PERFORM 1D IFFT ON EACH COLUMN

%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 :

%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));

%INVERSE FOURIER TRANSFORM

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

Like "IMAGE PROCESSING" page