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

Private GIT Repository
2a7f684268d196e961e19d39b629c3cd29f69973
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / matlab / ex_pm2_pls.m
1 %% EXAMPLE OF MULTI-LAYERED EMBEDDING - +-2 PAYLOAD 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 [d stego n_msg_bits l] = stc_pm2_pls_embed(cover, costs, msg, h);
19 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
20
21 if all(extr_msg==msg)
22     fprintf('Message was embedded and extracted correctly.\n');
23     fprintf('  %d bits embedded => %d bits in 3LSB, %d bits in 2LSB and %d bits in LSB.\n', ...
24         sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2), n_msg_bits(3));
25     fprintf('  achieved coding_loss = %4.2f%%\n', l*100);
26 end