]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/matlab/ex_pm2_dls.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
2b0e511917e9ff73c000175c7d9d766a58be669e
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / matlab / ex_pm2_dls.m
1 %% EXAMPLE OF MULTI-LAYERED EMBEDDING - +-2 DISTORTION LIMITED SENDER
2 % implemented using syndrome-trellis codes
3 clc; clear;
4
5 n = 1e+5; % use n pixels
6 m = n/2;  % embed m bits
7 h = 10;   % use STCs with constraint_height = 10. Try values between 7 and 12.
8
9 cover = int32(256*rand(1,n));  % generate random cover pixels
10 msg = uint8(rand(1,m));        % generate m random message bits
11
12 % cost can be defined arbitrarily, this is just a simple example
13 costs = zeros(5, n, 'single'); % for each pixel, assign cost of being changed
14 costs(:,1) = [1e+5 100 0 1 5]; % cost of changing the first cover pixel by -2, -1, 0, +1, +2
15 costs([1 5],2:end) = 4;        % cost of changing pixels by -2 and +2
16 costs([2 4],2:end) = 1;        % cost of changing pixels by -1 and +1
17
18 l = 0.08;           % expected coding loss
19 target_dist = 1000; % target distortion in the distortion-limited sender
20 [d stego n_msg_bits l] = stc_pm2_dls_embed(cover, costs, msg, target_dist, l, h);
21 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
22
23 if all(extr_msg==msg(1:sum(n_msg_bits)))
24     fprintf('Message was embedded and extracted correctly.\n');
25     fprintf('  %d bits embedded => %d bits in 3LSB, %d bits in 2LSB and %d bits in LSB.\n', ...
26         sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2), n_msg_bits(3));
27     fprintf('  achieved coding_loss = %4.2f%%\n', l*100);
28     fprintf('  distortion caused by embedding = %g required = %g\n', d, target_dist);
29 end