3 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
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 - +-2 DISTORTION LIMITED SENDER</title><meta name="generator" content="MATLAB 7.9"><meta name="date" content="2010-12-06"><meta name="m-file" content="ex_pm2_dls"><style type="text/css">
12 background-color: white;
26 /* Make the text shrink to fit narrow windows, but not stretch too far in
28 p,h1,h2,div.content div {
31 width: auto !important; width: 600px;
39 pre.codeinput {word-wrap:break-word; width:100%;}
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}
65 </style></head><body><div class="content"><h1>EXAMPLE OF MULTI-LAYERED EMBEDDING - +-2 DISTORTION LIMITED SENDER</h1><p>implemented using syndrome-trellis codes</p><pre class="codeinput">clc; clear;
67 n = 1e+5; <span class="comment">% use n pixels</span>
68 m = n/2; <span class="comment">% embed m bits</span>
69 h = 10; <span class="comment">% use STCs with constraint_height = 10. Try values between 7 and 12.</span>
71 cover = int32(256*rand(1,n)); <span class="comment">% generate random cover pixels</span>
72 msg = uint8(rand(1,m)); <span class="comment">% generate m random message bits</span>
74 <span class="comment">% cost can be defined arbitrarily, this is just a simple example</span>
75 costs = zeros(5, n, <span class="string">'single'</span>); <span class="comment">% for each pixel, assign cost of being changed</span>
76 costs(:,1) = [1e+5 100 0 1 5]; <span class="comment">% cost of changing the first cover pixel by -2, -1, 0, +1, +2</span>
77 costs([1 5],2:end) = 4; <span class="comment">% cost of changing pixels by -2 and +2</span>
78 costs([2 4],2:end) = 1; <span class="comment">% cost of changing pixels by -1 and +1</span>
80 l = 0.08; <span class="comment">% expected coding loss</span>
81 target_dist = 1000; <span class="comment">% target distortion in the distortion-limited sender</span>
82 [d stego n_msg_bits l] = stc_pm2_dls_embed(cover, costs, msg, target_dist, l, h);
83 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
85 <span class="keyword">if</span> all(extr_msg==msg(1:sum(n_msg_bits)))
86 fprintf(<span class="string">'Message was embedded and extracted correctly.\n'</span>);
87 fprintf(<span class="string">' %d bits embedded => %d bits in 3LSB, %d bits in 2LSB and %d bits in LSB.\n'</span>, <span class="keyword">...</span>
88 sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2), n_msg_bits(3));
89 fprintf(<span class="string">' achieved coding_loss = %4.2f%%\n'</span>, l*100);
90 fprintf(<span class="string">' distortion caused by embedding = %g required = %g\n'</span>, d, target_dist);
91 <span class="keyword">end</span>
92 </pre><pre class="codeoutput">Message was embedded and extracted correctly.
93 7771 bits embedded => 3546 bits in 3LSB, 2110 bits in 2LSB and 2115 bits in LSB.
94 achieved coding_loss = 13.83%
95 distortion caused by embedding = 992 required = 1000
96 </pre><p class="footer"><br>
97 Published with MATLAB® 7.9<br></p></div><!--
98 ##### SOURCE BEGIN #####
99 %% EXAMPLE OF MULTI-LAYERED EMBEDDING - +-2 DISTORTION LIMITED SENDER
100 % implemented using syndrome-trellis codes
103 n = 1e+5; % use n pixels
104 m = n/2; % embed m bits
105 h = 10; % use STCs with constraint_height = 10. Try values between 7 and 12.
107 cover = int32(256*rand(1,n)); % generate random cover pixels
108 msg = uint8(rand(1,m)); % generate m random message bits
110 % cost can be defined arbitrarily, this is just a simple example
111 costs = zeros(5, n, 'single'); % for each pixel, assign cost of being changed
112 costs(:,1) = [1e+5 100 0 1 5]; % cost of changing the first cover pixel by -2, -1, 0, +1, +2
113 costs([1 5],2:end) = 4; % cost of changing pixels by -2 and +2
114 costs([2 4],2:end) = 1; % cost of changing pixels by -1 and +1
116 l = 0.08; % expected coding loss
117 target_dist = 1000; % target distortion in the distortion-limited sender
118 [d stego n_msg_bits l] = stc_pm2_dls_embed(cover, costs, msg, target_dist, l, h);
119 extr_msg = stc_ml_extract(stego, n_msg_bits, h);
121 if all(extr_msg==msg(1:sum(n_msg_bits)))
122 fprintf('Message was embedded and extracted correctly.\n');
123 fprintf(' %d bits embedded => %d bits in 3LSB, %d bits in 2LSB and %d bits in LSB.\n', ...
124 sum(n_msg_bits), n_msg_bits(1), n_msg_bits(2), n_msg_bits(3));
125 fprintf(' achieved coding_loss = %4.2f%%\n', l*100);
126 fprintf(' distortion caused by embedding = %g required = %g\n', d, target_dist);
129 ##### SOURCE END #####