adielab7
adielab7
No:
Spectral representation for enhancement and coding – DCT and
Date : Dithering
AIM:
X = [9 8 6 1; 5 6 7 3; 7 10 11 9; 13 14 15 16];
[m, n] = size(X);
f = zeros(m, n);
for u = 0:m-1
for v = 0:n-1
S = 0;
if u == 0
alpha_u = sqrt(1/m);
else
alpha_u = sqrt(2/m);
end
if v == 0
alpha_v = sqrt(1/n);
else
alpha_v = sqrt(2/n);
end
for x = 0:m-1
for y = 0:n-1
S = S + (X(x+1, y+1) * cos(((2*x+1)*u*pi)/(2*m)) * cos(((2*y+1)*v*pi)/(2*n)));
end
end
f(u+1, v+1) = alpha_u * alpha_v * S;
end
end
disp('Manual DCT:');
disp(f);
d = dct2(X);
disp('DCT using dct2():');
disp(d);
X_idct = idct2(d);
disp('IDCT using idct2():');
disp(X_idct);
Output
img =
rgb2gray(imread('kayal.png')); img
= imresize(img, [200 200]);
img = double(img);
[m, n] = size(img);
f = zeros(m, n);
for u = 0:m-1
for v = 0:n-1
S = 0;
if u == 0
alpha_u = sqrt(1/m);
else
alpha_u = sqrt(2/m);
end
if v == 0
alpha_v = sqrt(1/n);
else
alpha_v = sqrt(2/n);
end
for x = 0:m-1
for y = 0:n-1
S = S + (img(x+1, y+1) * cos(((2*x+1)*u*pi)/(2*m)) * cos(((2*y+1)*v*pi)/(2*n)));
end
end
f(u+1, v+1) = alpha_u * alpha_v * S;
end
end
figure;
subplot(1,3,1), imshow(uint8(img)), title('Original Image','FontName','Arial','FontSize',6);
subplot(1,3,2), imshow(log(abs(f)+1), []), title('DCT of
Image','FontName','Arial','FontSize',6);
subplot(1,3,3), imshow(uint8(X_reconstructed)), title('Reconstructed
Image','FontName','Arial','FontSize',6);
Output:
clc;
clear all;
close all;
x = rgb2gray(imread('kayal.png'));
[m, n] = size(x);
pts = imhist(x);
valley_pts = islocalmin(pts);
thr = find(valley_pts, 1);
img = x > thr;
subplot(1,2,1);
imshow(x);
title('Original Image');
subplot(1,2,2);
imshow(img);
title('Thresholded Image');
Output:
clc;
clear all;
close all;
B4 = [ 0 8 2 10;
12 4 14 6;
3 11 1 9;
15 7 13 5];
Output:
Inferences:
Result:
Thus we have successfully enhanced and encoded images using spectral representation
techniques such as Discrete Cosine Transform (DCT) and Segmentation using
Dithering.