-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabseven_three.m
More file actions
59 lines (56 loc) · 1.94 KB
/
labseven_three.m
File metadata and controls
59 lines (56 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%Title: To compress an image with Discrete Cosine Transformation.
%Developed By: Rabi Raj Khadka
%Date: July 3, 2017
%-------------------------------------------------------------------
%Three critical statements
%-------------------------------------------------------------------
close all;
clear variables;
clc;
%-------------------------------------------------------------------
%Image input
%-------------------------------------------------------------------
xorg=imread('img\neuromancer.jpg');
x=rgb2gray(xorg);
F=dct2(x);%built in DCT
ff=idct2(F);%Built in IDCT
%-------------------------------------------------------------------
%Block wise DCT Implementation
%-------------------------------------------------------------------
[r,c]=size(x);
%-------------------------------------------------------------------
%Variable Initialization
%-------------------------------------------------------------------
DF=zeros(r,c);
DFF=DF;
IDF=DF;
IDFF=DF;
depth=4;
N=8; %Size of transformation block
for i=1:N:r
for j=1:N:c
f=x(i:i+N-1,j:j+N-1);
df=dct2(f);
DF(i:i+N-1,j:j+N-1)=df;% DCT of the blocks
dff=idct2(df);
DFF(i:i+N-1,j:j+N-1)=dff; %Inverese DCT of the blocks;
df(N:-1:depth+1,:)=0;
df(:,N:-1:depth+1)=0;
IDF(i:i+N-1,j:j+N-1)=df;%DCT of blocks with depth consideration)
dff=idct(df);
IDFF(i:i+N-1,j:j+N-1)=dff; %Inverese DCT of blocks with depth considered)
end
end
A=DFF/255;
imwrite(A,'DCTcompressed.jpg');
B=IDFF/255;
imwrite(B,'IDCTcompressed.jpg');
figure;
subplot(241),imshow(x),title('Gray Scale Image');
subplot(242),imshow(F*0.01),title('Built-in DCT ');
subplot(246),imshow(ff/255),title('Built-in IDCT');
subplot(243),imshow(DF),title('DCT Block Image');
subplot(247),imshow(DFF/255),title('IDCT Block Image');
subplot(244),imshow(A),title('DCT Compressed Image');
subplot(248),imshow(B),title('IDCT Compressed Image');
subplot(245),imshow(xorg),title('Original Image');