-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.m
59 lines (55 loc) · 1.37 KB
/
extract.m
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
stegoimg=stegoimg.*255;
%Performing dwt on stego-image
[A H V D] = dwt2(stegoimg,'haar');
%A has approximation band.
%H has horizontal band.
%V has vertical band.
%D has diagonal band.
[bx by] = size(A); %To store the size of the bands.
%lbit contains the total number of bits in the bit stream.
lbit=bcnt*3;
%The bits are stored in the diagonal.
x=1; %Tracks x coordinate.
%bits = zeros(1,lbit); %To store the bits.
bits = ''; %To store the bits.
while x<=bx
y=1;
while y<=by
num = int8(mod(sD(x,y),8));
bnum = dec2bin(num);
if num==0 || num==1
bits=[bits '00'];
end
if num==2 || num==3
bits = [bits '0'];
end
bits = [bits bnum];
y = y + 1;
end
x = x + 1;
end
bits=bits(1,1:lbit);
%Traverse through the huffman tree to find the corresponding pixel values
%and then assign it to the new image matrix to obtain the secret image.
i=1;
cnt=1;
while i<=sx
j=1;
while j<=sy
temp=hufftree;
while isa(temp,'cell')
if bits(cnt)=='0'
temp=temp{1};
else
temp=temp{2};
end
cnt=cnt+1;
end
simg(i,j)=temp-1;
j=j+1;
end
i=i+1;
end
%Displaying the secret image.
secretimg=mat2gray(simg);
imtool(secretimg);