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

Private GIT Repository
59bfc82538b625da9fb20467a91b1d5de20751e4
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / matlab / html / ex_pm1_dls.html
1
2 <!DOCTYPE html
3   PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html><head>
5       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6    <!--
7 This HTML is auto-generated from an M-file.
8 To make changes, update the M-file and republish this document.
9       --><title>EXAMPLE OF MULTI-LAYERED EMBEDDING - +-1 DISTORTION LIMITED SENDER</title><meta name="generator" content="MATLAB 7.9"><meta name="date" content="2010-12-06"><meta name="m-file" content="ex_pm1_dls"><style type="text/css">
10
11 body {
12   background-color: white;
13   margin:10px;
14 }
15
16 h1 {
17   color: #990000; 
18   font-size: x-large;
19 }
20
21 h2 {
22   color: #990000;
23   font-size: medium;
24 }
25
26 /* Make the text shrink to fit narrow windows, but not stretch too far in 
27 wide windows. */ 
28 p,h1,h2,div.content div {
29   max-width: 600px;
30   /* Hack for IE6 */
31   width: auto !important; width: 600px;
32 }
33
34 pre.codeinput {
35   background: #EEEEEE;
36   padding: 10px;
37 }
38 @media print {
39   pre.codeinput {word-wrap:break-word; width:100%;}
40
41
42 span.keyword {color: #0000FF}
43 span.comment {color: #228B22}
44 span.string {color: #A020F0}
45 span.untermstring {color: #B20000}
46 span.syscmd {color: #B28C00}
47
48 pre.codeoutput {
49   color: #666666;
50   padding: 10px;
51 }
52
53 pre.error {
54   color: red;
55 }
56
57 p.footer {
58   text-align: right;
59   font-size: xx-small;
60   font-weight: lighter;
61   font-style: italic;
62   color: gray;
63 }
64
65   </style></head><body><div class="content"><h1>EXAMPLE OF MULTI-LAYERED EMBEDDING - +-1 DISTORTION LIMITED SENDER</h1><p>implemented using syndrome-trellis codes</p><pre class="codeinput">clc; clear;
66
67 n = 1e+5; <span class="comment">% use n pixels</span>
68 h = 12;   <span class="comment">% use STCs with constraint_height = 10. Try values between 7 and 12.</span>
69
70 cover = int32(256*rand(1,n));  <span class="comment">% generate random cover pixels</span>
71 msg = uint8(rand(1,n));        <span class="comment">% generate n random message bits, only some portion will be utilized</span>
72
73 costs = zeros(3, n, <span class="string">'single'</span>); <span class="comment">% for each pixel, assign cost of being changed</span>
74 costs(:,1) = [1 0 1];          <span class="comment">% cost of changing the first cover pixel by -1, 0, +1</span>
75 costs([1 3],2:end) = 1;        <span class="comment">% cost can be defined arbitrarily</span>
76
77 l = 0.08;           <span class="comment">% expected coding loss</span>
78 target_dist = 1000; <span class="comment">% target distortion in the distortion-limited sender</span>
79 [d stego n_msg_bits l] = stc_pm1_dls_embed(cover, costs, msg, target_dist, l, h);
80 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
81
82 <span class="keyword">if</span> all(extr_msg==msg(1:sum(n_msg_bits)))
83     fprintf(<span class="string">'Message was embedded and extracted correctly.\n'</span>);
84     fprintf(<span class="string">'  %d bits embedded =&gt; %d bits in 2LSB and %d bits in LSB.\n'</span>, <span class="keyword">...</span>
85         sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2));
86     fprintf(<span class="string">'  achieved coding_loss = %4.2f%%\n'</span>, l*100);
87     fprintf(<span class="string">'  distortion caused by embedding = %g required = %g\n'</span>, d, target_dist);
88 <span class="keyword">end</span>
89 </pre><pre class="codeoutput">Message was embedded and extracted correctly.
90   7771 bits embedded =&gt; 3545 bits in 2LSB and 4226 bits in LSB.
91   achieved coding_loss = 11.66%
92   distortion caused by embedding = 963 required = 1000
93 </pre><p class="footer"><br>
94       Published with MATLAB&reg; 7.9<br></p></div><!--
95 ##### SOURCE BEGIN #####
96 %% EXAMPLE OF MULTI-LAYERED EMBEDDING - +-1 DISTORTION LIMITED SENDER
97 % implemented using syndrome-trellis codes
98 clc; clear;
99
100 n = 1e+5; % use n pixels
101 h = 12;   % use STCs with constraint_height = 10. Try values between 7 and 12.
102
103 cover = int32(256*rand(1,n));  % generate random cover pixels
104 msg = uint8(rand(1,n));        % generate n random message bits, only some portion will be utilized
105
106 costs = zeros(3, n, 'single'); % for each pixel, assign cost of being changed
107 costs(:,1) = [1 0 1];          % cost of changing the first cover pixel by -1, 0, +1
108 costs([1 3],2:end) = 1;        % cost can be defined arbitrarily
109
110 l = 0.08;           % expected coding loss
111 target_dist = 1000; % target distortion in the distortion-limited sender
112 [d stego n_msg_bits l] = stc_pm1_dls_embed(cover, costs, msg, target_dist, l, h);
113 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
114
115 if all(extr_msg==msg(1:sum(n_msg_bits)))
116     fprintf('Message was embedded and extracted correctly.\n');
117     fprintf('  %d bits embedded => %d bits in 2LSB and %d bits in LSB.\n', ...
118         sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2));
119     fprintf('  achieved coding_loss = %4.2f%%\n', l*100);
120     fprintf('  distortion caused by embedding = %g required = %g\n', d, target_dist);
121 end
122
123 ##### SOURCE END #####
124 --></body></html>