1 %% EXAMPLE OF MULTI-LAYERED EMBEDDING - +-1 DISTORTION LIMITED SENDER
2 % implemented using syndrome-trellis codes
5 n = 1e+5; % use n pixels
6 h = 12; % use STCs with constraint_height = 10. Try values between 7 and 12.
8 cover = int32(256*rand(1,n)); % generate random cover pixels
9 msg = uint8(rand(1,n)); % generate n random message bits, only some portion will be utilized
11 costs = zeros(3, n, 'single'); % for each pixel, assign cost of being changed
12 costs(:,1) = [1 0 1]; % cost of changing the first cover pixel by -1, 0, +1
13 costs([1 3],2:end) = 1; % cost can be defined arbitrarily
15 l = 0.08; % expected coding loss
16 target_dist = 1000; % target distortion in the distortion-limited sender
17 [d stego n_msg_bits l] = stc_pm1_dls_embed(cover, costs, msg, target_dist, l, h);
18 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
20 if all(extr_msg==msg(1:sum(n_msg_bits)))
21 fprintf('Message was embedded and extracted correctly.\n');
22 fprintf(' %d bits embedded => %d bits in 2LSB and %d bits in LSB.\n', ...
23 sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2));
24 fprintf(' achieved coding_loss = %4.2f%%\n', l*100);
25 fprintf(' distortion caused by embedding = %g required = %g\n', d, target_dist);