You are on page 1of 10

DFT and DCT

close all
clear all
clc
%% Image Read
% I = imread ('C\Users\User\Destop\Tulips.jpg');
I = imread('..\Tulips.jpg');
I_gray= rgb2gray(I);
I_double = double(I_gray);

%% Dft
N = size(I_double, 1);
M = zeros(N,N);

for ii = 1:N
for jj = 1:N
M(ii,jj) = exp (-1i*2*pi*(ii-1)*(jj-1)/N);
end
end
%display(M)

I_row = (M * I_double)/N;
% I_col = (M * I_row.')/N;

%% Dft
N = size(I_double, 2);
M = zeros(N,N);

for ii = 1:N
for jj = 1:N
M(ii,jj) = exp (-1i*2*pi*(ii-1)*(jj-1)/N);
end
end
%display(M)

% I_row = (M * I_double)/N;
I_col = (M * I_row.')/N;

%% Display
figure('Name', 'IPMV')
subplot(2,2,1)
imshow(I)
title('Original image')
subplot(2,2,2)
imshow(I_gray)
title('gray image')
subplot(2,2,3)
imshow(abs(I_row))
subplot(2,2,4)
imshow(abs(I_col))
EXP 2

close all
clear all
clc

%%
I = imread('Data\Tulips.jpg');
I_gray = rgb2gray(I);

%% Image negative
I_neg = 255- I_gray;

%% Log transform
I_log = uint8(log10(double(1+I_gray))/log10(256)*255);

%% Gamma transform
gamma = 2;
I_gamma = uint8(double(I_gray).^gamma/255^gamma*255);

%% Display
figure('Name', 'Exp-2')
subplot(2,2,1)
imshow(I_gray)
title('Original Image')
subplot(2,2,2)
imshow(I_neg)

title('Negative Image')
subplot(2,2,3)
imshow(I_log)
title('Log transformed Image')

subplot(2,2,4)
imshow(I_gamma)
title('Log transformed Image')
EXP 3

close all
clear all
clc

%%
I = imread('Data\Tulips.jpg');
I_gray = rgb2gray(I);

%% Image stretching
rmax = max(max(I_gray));
rmin = min(I_gray(:));

% rmin = 50;
% rmax = 150;
I_str = uint8((I_gray-rmin)/(rmax - rmin)*255);

%% Image equalization
I_eq = histeq(I_gray);

%% Display
figure('Name', 'Exp-3')
subplot(2,2,1)
imshow(I_gray)
title('Original Image')

subplot(2,2,2)
imshow(I_str)
title('Stretched Image')

subplot(2,1,2)
imshow(I_eq)
title('Equalized Image')
EXP 4

close all
clear all
clc

%%
I = imread('Data\Tulips.jpg');
I_gray = rgb2gray(I);

%% LPF
N = 30;
h = ones(N, N)/N^2;

I_lpf = imfilter(I_gray, h);

%% HPF
h = [-1, -1, -1;
-1, 8, -1;
-1, -1, -1];

I_hpf = imfilter(I_gray, h);

%% High boost
h = [0, -1, 0;
-1, 6, -1;
0, -1, 0];

I_hb = imfilter(I_gray, h);

%% Median
I_med = medfilt2(I_gray);

%% Display
figure('Name', 'Exp-4')
subplot(2,3,1)
imshow(I_gray)
title('Original Image')

subplot(2,3,2)
imshow(I_lpf)
title('Lowpass filtered Image')

subplot(2,3,3)
imshow(I_hpf)
title('Highpass filtered Image')

subplot(2,3,4)
imshow(I_med)
title('Median filtered Image')

subplot(2,3,5)
imshow(I_hb)
title('High Boost filtered Image')
Exp 7:

clc
clear all;
%%
I = imread('Data\blobs.png');
hor=[1,1,1;0,0,0;-1,-1,-1];
ver=[-1,0,1;-1,0,1;-1,0,1];
c=imfilter(I,hor);
d=imfilter(I,ver);
e=c+d;
subplot(2,2,1);
imshow(I);
subplot(2,2,2);
imshow(c);
subplot(2,2,3);
imshow(d);
subplot(2,2,4);
imshow(e);
Exp6

clc
clear all;
%%
I = imread('Data\coins.png');
% I_gray = rgb2gray(I);
subplot(2,4,1)
imshow(I)
title('Original Image')

%% Image negative
I_neg = imcomplement(I);
subplot(2,4,2)
imshow(I_neg)
title('Negative Image')
%% Binary
I_bw = im2bw(I_neg);
subplot(2,4,3)
imshow(I_bw)
title('Binary Image')
%% output section
se = strel('square',4);
I_bwc = imclose(I_bw, se);
I_bwo = imopen ( I_bwc, se);
subplot(2,4,4)
imshow(I_bwc)
title('Closing the Relationship')
subplot(2,4,5)
imshow(I_bwo)
title('Opening Image')

%% interesection of Open and Close


mask = I_bw&I_bwo;
subplot(2,4,6);
imshow(mask);
title('And of the Image');

You might also like