-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathset_watermark.m
101 lines (90 loc) · 2.64 KB
/
set_watermark.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
% Read files and initialize
[x,fs] = wavread('Imsad.wav');
x = x(1:30*fs); x = x(:);
L = length(x);
N = 512;
win = blackman(N+1);
win = win(1:end-1);
num_frame = L/N;
y = zeros(1,L);
im = imread('leo_re.jpg');
S = size(im);
row = 1;
column = 1;
count2 = 0;
mask_no = zeros(1,num_frame);
for mm = 1:num_frame
% Framing and FFT
tt = (mm-1)*N+1 : mm*N;
X = fft(x(tt));
% Find Frequency Threshold
M = find_mask(X,fs);
plot(M);
X_tmp = X;
pix = [];
if (column+11) > S(2) && (row+1) <= S(1)
pix = [im(row,column:S(2),:) im(row+1,1:(column+11-S(2)),:)];
row = row +1;
column = column+12-S(2);
elseif (column+11) > S(2) && row == S(1)
pix = im(row,column:S(2),:);
elseif row <= S(1)
pix = im(row,column:(column+11),:);
column = column+12;
end
S2 = size(pix);
row2 = 1;
column2 = 1;
color = 1;
count = 1;
% In-audible Removal
if ~isempty(pix)
imsg = dec2bin(pix(row2,column2,color),8);
for k = 1:(N/2)
if 20*log(abs(X(k))) < M(k)
count2 = count2+1;
if imsg(count) == '1' && imsg(count+1) == '1'
msg = exp(-1.9);
elseif imsg(count) == '1' && imsg(count+1) == '0'
msg = exp(-3.9);
elseif imsg(count) == '0' && imsg(count+1) == '1'
msg = exp(-5.9);
else
msg = exp(-10);
end
if k~=1
X(k) = msg*exp(1i*angle(X(k)));
X(N-k+2) = msg*exp(1i*angle(X(N-k+2)));
else
X(k) = msg*exp(1i*angle(X(k)));
end
count = count+2;
if count > 8
count = 1;
color = color+1;
if color > 3
color = 1;
column2 = column2+1;
if column2 > S2(2)
column2 = 1;
row2 = row2+1;
end
end
end
if row2 > S2(1)
imsg = dec2bin(0,8);
else
imsg = dec2bin(pix(row2,column2,color),8);
end
end
end
end
% if mm == 1
% plot(20*log(abs(X)));
% end
mask_no(mm) = count2;
count2 = 0;
y(tt) = ifft(X);
end
y = y/max(abs(y));
wavwrite(y,fs,'masked.wav');