Commit 95f76ce882085a85eb304d47d0cc33104b5bb1be
1 parent
f4fb4381
Exists in
master
theis finished.论文查重2.1 ( ̄ˇ ̄)
Showing
12 changed files
with
337 additions
and
52 deletions
Show diff stats
mdata/ANALYSIS.py
| ... | ... | @@ -9,14 +9,27 @@ import matplotlib as mpl |
| 9 | 9 | import matplotlib.pyplot as plt |
| 10 | 10 | import seaborn as sns |
| 11 | 11 | |
| 12 | +import numpy as np | |
| 13 | +import matplotlib.pyplot as plt | |
| 14 | +import seaborn as sns | |
| 15 | +from .. import mjpeg | |
| 16 | +from ..mjpeg import base | |
| 17 | +from ..msteg.steganography import LSB, F3, F4, F5 | |
| 18 | + | |
| 12 | 19 | np.random.seed(sum(map(ord, "whoami"))) |
| 13 | -plt.ticklabel_format(style='sci', axis='both', scilimits=(1, 4)) | |
| 20 | + | |
| 21 | +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, | |
| 22 | + 61908L, 63014L, 5908L, 59816L, 56765L] | |
| 23 | + | |
| 24 | +# plt.ticklabel_format(style='sci', axis='both', scilimits=(0, 0)) | |
| 25 | +plt.ticklabel_format(style='sci', axis='both') | |
| 14 | 26 | |
| 15 | 27 | package_dir = os.path.dirname(os.path.abspath(__file__)) |
| 16 | 28 | |
| 17 | 29 | |
| 18 | 30 | def anal_ILSVRC(): |
| 19 | - df_ILS = pd.read_csv('../res/file-tag.tsv', names=['hash', 'width', 'height', 'size', 'quality'], sep='\t') | |
| 31 | + df_ILS = pd.read_csv('../res/file-tag.tsv', | |
| 32 | + names=['hash', 'width', 'height', 'size', 'quality'], sep='\t') | |
| 20 | 33 | print df_ILS[df_ILS.size < 2000000] |
| 21 | 34 | print df_ILS.describe() |
| 22 | 35 | # df_ILS.boxplot(column='size') |
| ... | ... | @@ -68,7 +81,8 @@ def anal_ILSVRC(): |
| 68 | 81 | |
| 69 | 82 | |
| 70 | 83 | def anal_ILSVRC_Test(): |
| 71 | - df_ILS_T = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','class'], sep='\t') | |
| 84 | + df_ILS_T = pd.read_csv('../res/file-tag-test.tsv', | |
| 85 | + names=['hash', 'width', 'height', 'size', 'quality', 'class'], sep='\t') | |
| 72 | 86 | print df_ILS_T |
| 73 | 87 | print df_ILS_T.size.describe() |
| 74 | 88 | |
| ... | ... | @@ -80,23 +94,35 @@ def anal_ILSVRC_Test(): |
| 80 | 94 | df_ILS_T['class2'] = np.zeros(length, np.int32) |
| 81 | 95 | df_ILS_T.to_csv('../res/file-tag-test.tsv', header=False, index=False, sep='\t') |
| 82 | 96 | |
| 97 | + | |
| 83 | 98 | def anal_0000(): |
| 84 | - df_ILS = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','chosen','class'], sep='\t') | |
| 99 | + df_ILS = pd.read_csv(os.path.join(package_dir, '../res/file-tag-test.tsv'), | |
| 100 | + names=['hash', 'width', 'height', 'size', 'quality', 'chosen', 'class'], | |
| 101 | + sep='\t') | |
| 85 | 102 | length = df_ILS.shape[0] |
| 86 | 103 | print df_ILS.size.describe() |
| 87 | 104 | print df_ILS.size.order().iloc[map(lambda x: x * length, [1.0 / 3, 2.0 / 3, 0.9999])] |
| 88 | 105 | |
| 106 | + print df_ILS.size[df_ILS.size == 166500].count() / 4592.0 | |
| 107 | + print df_ILS.size[df_ILS.size == 187500].count() / 4592.0 | |
| 108 | + print df_ILS.size[df_ILS.size == 250000].count() / 4592.0 | |
| 109 | + | |
| 89 | 110 | print df_ILS.size[df_ILS.size <= 166500].count() |
| 90 | 111 | print df_ILS.size[(df_ILS['size'] > 166500) & (df_ILS['size'] <= 187500)].count() |
| 91 | 112 | print df_ILS.size[df_ILS.size > 187500].count() |
| 92 | 113 | |
| 93 | - df_ILS.hist(column='size',bins=100) | |
| 114 | + plt.ticklabel_format(style='sci', axis='both') | |
| 115 | + df_ILS.hist(column='size', bins=100) | |
| 116 | + plt.title('') | |
| 117 | + plt.xlabel("Image size") | |
| 118 | + plt.ylabel("Frequency") | |
| 94 | 119 | plt.show() |
| 95 | 120 | |
| 96 | 121 | |
| 97 | - | |
| 98 | 122 | def pre_crop(): |
| 99 | - df_ILS = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','chosen','class'], sep='\t') | |
| 123 | + df_ILS = pd.read_csv(os.path.join(package_dir, '../res/file-tag-test.tsv'), | |
| 124 | + names=['hash', 'width', 'height', 'size', 'quality', 'chosen', 'class'], | |
| 125 | + sep='\t') | |
| 100 | 126 | print df_ILS.shape |
| 101 | 127 | print df_ILS[(df_ILS['width'] >= 300) & (df_ILS['height'] >= 300)].shape |
| 102 | 128 | |
| ... | ... | @@ -105,23 +131,250 @@ def pre_crop(): |
| 105 | 131 | # 400x400 932 0.202 |
| 106 | 132 | |
| 107 | 133 | |
| 134 | +def plot_hist(): | |
| 135 | + dat_performance = np.array([ | |
| 136 | + [100, 0.583396, 30.847788, 57.884814, 89.315998, 1.471087, 29.364628, 9.114235, 10.585322, | |
| 137 | + 39.94995, 2.235697366], | |
| 138 | + [200, 1.147411, 62.815709, 118.217859, 182.180979, 3.008692, 37.920278, 19.589578, 22.59827, | |
| 139 | + 60.518548, 3.010332948], | |
| 140 | + [500, 2.763806, 162.806317, 299.778606, 465.348729, 6.81705, 88.291989, 73.446282, | |
| 141 | + 80.263332, 168.555321, 2.760807112], | |
| 142 | + [1000, 6.372794, 329.023151, 600.438977, 935.834922, 15.644418, 159.951099, 186.335413, | |
| 143 | + 201.979831, 361.93093, 2.585672692], | |
| 144 | + [2000, 14.960961, 679.357936, 1256.341536, 1950.660433, 31.699596, 313.154748, 387.063702, | |
| 145 | + 418.763298, 731.918046, 2.665135043], | |
| 146 | + [5000, 39.880657, 1652.537536, 3067.98039, 4760.398583, 73.070203, 694.454719, 898.458633, | |
| 147 | + 971.528836, 1665.983555, 2.857410308]]) | |
| 148 | + | |
| 149 | + dat_performance = np.transpose(dat_performance) | |
| 150 | + data_size, serial_tot, spark_io, spark_proc, spark_tot = dat_performance[0], dat_performance[4], \ | |
| 151 | + dat_performance[8], dat_performance[6], \ | |
| 152 | + dat_performance[9] | |
| 153 | + | |
| 154 | + data_size = data_size.astype(int) | |
| 155 | + A = [spark_io, spark_proc] | |
| 156 | + E = np.arange(len(data_size)) | |
| 157 | + bar_width = 0.5 | |
| 158 | + # plt.bar(E, spark_io, width=bar_width) | |
| 159 | + # plt.bar(E, spark_proc, color='#e74c3c', width=bar_width, bottom=spark_io) | |
| 160 | + # plt.xlabel("Data size") | |
| 161 | + # plt.ylabel("Time(s)") | |
| 162 | + # plt.xticks(E + bar_width / 2, data_size) | |
| 163 | + # # plt.xticks(range(len(data_size)), data_size, size='small') | |
| 164 | + # # plt.ylim(ymax=300000) | |
| 165 | + # plt.show() | |
| 166 | + | |
| 167 | + # mpl.rcParams.update({'font.size': 5}) | |
| 108 | 168 | |
| 169 | + fig, ax = plt.subplots() | |
| 170 | + rects1 = ax.bar(E, spark_io, bar_width) | |
| 171 | + rects2 = ax.bar(E, spark_proc, bar_width, color='#e74c3c', bottom=spark_io) | |
| 109 | 172 | |
| 110 | -if __name__ == '__main__': | |
| 111 | - # anal_ILSVRC() | |
| 112 | - # anal_ILSVRC_Test() | |
| 113 | - # anal_0000() | |
| 114 | - # print timeit.timeit("anal_ILSVRC()", setup="from __main__ import anal_ILSVRC", number=1) | |
| 173 | + # add some text for labels, title and axes ticks | |
| 174 | + plt.xlabel("Data size") | |
| 175 | + ax.set_ylabel('Time(s)') | |
| 176 | + # ax.set_title('IO ratio') | |
| 177 | + ax.set_xticks(E + bar_width / 2) | |
| 178 | + ax.set_xticklabels(data_size) | |
| 115 | 179 | |
| 180 | + ax.legend((rects1[0], rects2[0]), ('IO', 'CPU'), loc=2) | |
| 116 | 181 | |
| 117 | - pre_crop() | |
| 118 | - pass | |
| 182 | + height1 = [rect.get_height() for rect in rects1] | |
| 183 | + height2 = [rect.get_height() for rect in rects2] | |
| 184 | + for i in range(len(rects1)): | |
| 185 | + height = rects1[i].get_height() + rects2[i].get_height() | |
| 186 | + ax.text(rects1[i].get_x() + rects1[i].get_width() / 2, 1.005 * height, '%d%%' % | |
| 187 | + int((100 * 1.0*height1[i]/height)), | |
| 188 | + ha='center', va='bottom') | |
| 189 | + | |
| 190 | + # height1 = [rect.get_height() for rect in rects1] | |
| 191 | + # height2 = [rect.get_height() for rect in rects2] | |
| 192 | + # for i in range(len(rects1)): | |
| 193 | + # ax.text(rects1[i].get_x() + rects1[i].get_width() / 2, 0.5 * height1[i], '%f' % (0.1 * | |
| 194 | + # height1[ | |
| 195 | + # i] / | |
| 196 | + # height2[ | |
| 197 | + # i]), | |
| 198 | + # ha='center', va='bottom') | |
| 199 | + | |
| 200 | + | |
| 201 | + plt.show() | |
| 202 | + | |
| 203 | + | |
| 204 | +def plot_line_performance(): | |
| 205 | + # performance | |
| 206 | + dat_performance = np.array([ | |
| 207 | + [100, 0.583396, 30.847788, 57.884814, 89.315998, 1.471087, 29.364628, 9.114235, 10.585322, | |
| 208 | + 39.94995, 2.235697366], | |
| 209 | + [200, 1.147411, 62.815709, 118.217859, 182.180979, 3.008692, 37.920278, 19.589578, 22.59827, | |
| 210 | + 60.518548, 3.010332948], | |
| 211 | + [500, 2.763806, 162.806317, 299.778606, 465.348729, 6.81705, 88.291989, 73.446282, | |
| 212 | + 80.263332, 168.555321, 2.760807112], | |
| 213 | + [1000, 6.372794, 329.023151, 600.438977, 935.834922, 15.644418, 159.951099, 186.335413, | |
| 214 | + 201.979831, 361.93093, 2.585672692], | |
| 215 | + [2000, 14.960961, 679.357936, 1256.341536, 1950.660433, 31.699596, 313.154748, 387.063702, | |
| 216 | + 418.763298, 731.918046, 2.665135043], | |
| 217 | + [5000, 39.880657, 1652.537536, 3067.98039, 4760.398583, 73.070203, 694.454719, 898.458633, | |
| 218 | + 971.528836, 1665.983555, 2.857410308]]) | |
| 219 | + | |
| 220 | + dat_performance = np.transpose(dat_performance) | |
| 221 | + data_size, serial_tot, spark_io, spark_proc, spark_tot = dat_performance[0], dat_performance[4], \ | |
| 222 | + dat_performance[8], dat_performance[6], \ | |
| 223 | + dat_performance[9] | |
| 224 | + | |
| 225 | + # sns.set_style("white") | |
| 226 | + # data_size = data_size.astype(int) | |
| 227 | + # plt.plot(range(len(data_size)), serial_tot, marker='o', label='serial total') | |
| 228 | + # plt.plot(range(len(data_size)), spark_tot, marker='o', linestyle='--', label='spark total') | |
| 229 | + # plt.plot(range(len(data_size)), spark_io, marker='o', linestyle=':', label='spark io') | |
| 230 | + # plt.plot(range(len(data_size)), spark_proc, marker='o', linestyle='-.', label='spark proc') | |
| 231 | + # plt.xlabel("Data size") | |
| 232 | + # plt.ylabel("Time(s)") | |
| 233 | + # plt.xticks(range(len(data_size)), data_size, size='small') | |
| 234 | + # plt.legend(loc=2) | |
| 235 | + # plt.show() | |
| 236 | + | |
| 237 | + plt.plot(data_size, serial_tot, marker='o', label='serial total') | |
| 238 | + plt.plot(data_size, spark_tot, marker='o', linestyle='--', label='spark total') | |
| 239 | + plt.plot(data_size, spark_io, marker='o', linestyle=':', label='spark io') | |
| 240 | + plt.plot(data_size, spark_proc, marker='o', linestyle='-.', label='spark proc') | |
| 241 | + plt.xlabel("Data size") | |
| 242 | + plt.ylabel("Time(s)") | |
| 243 | + plt.legend(loc=2) | |
| 244 | + plt.show() | |
| 119 | 245 | |
| 120 | 246 | |
| 247 | +def plot_line_io(): | |
| 248 | + # io | |
| 249 | + dat_io = np.array([ | |
| 250 | + [100, 10.585322, 29.364628, 39.94995, 10.286684, 27.079774, 37.366458, 49.995647, | |
| 251 | + 55.280739], | |
| 252 | + [200, 22.59827, 37.920278, 60.518548, 22.731275, 38.491461, 61.222736, 76.258928, | |
| 253 | + 83.836657], | |
| 254 | + [500, 80.263332, 88.291989, 168.555321, 64.610839, 88.241193, 152.852032, 177.039349, | |
| 255 | + 143.524813], | |
| 256 | + [1000, 201.979831, 159.951099, 361.93093, 172.359455, 158.694248, 331.053703, 467.126756, | |
| 257 | + 315.578952], | |
| 258 | + [2000, 418.763298, 313.154748, 731.918046, 390.990209, 313.085707, 704.075916, 802.138669, | |
| 259 | + 734.133909], | |
| 260 | + [5000, 971.528836, 694.454719, 1665.983555, 898.468232, 717.603061, 1616.071293, | |
| 261 | + 1860.610954, 1677.044038]]) | |
| 262 | + | |
| 263 | + dat_io = np.transpose(dat_io) | |
| 264 | + data_size, happybase_uncomp_io, happybase_uncomp_cpu, happybase_uncomp_tot, happybase_comp_io, happybase_comp_cpu, happybase_comp_tot, dist_uncomp, dist_comp = dat_io | |
| 265 | + # data_size = data_size.astype(int) | |
| 266 | + # plt.plot(range(len(data_size)), dist_uncomp, marker='o', label='dist-uncompressed total') | |
| 267 | + # plt.plot(range(len(data_size)), dist_comp, marker='o', label='dist-compressed total') | |
| 268 | + # plt.plot(range(len(data_size)), happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') | |
| 269 | + # plt.plot(range(len(data_size)), happybase_comp_tot, marker='o', label='happybase-compressed total') | |
| 270 | + # | |
| 271 | + # plt.plot(range(len(data_size)), happybase_uncomp_io, marker='o', linestyle='--', | |
| 272 | + # label='happybase-uncompressed io') | |
| 273 | + # plt.plot(range(len(data_size)), happybase_comp_io, marker='o', linestyle='--', | |
| 274 | + # label='happybase-compressed io') | |
| 275 | + # plt.plot(range(len(data_size)), happybase_uncomp_cpu, marker='o', linestyle='--', | |
| 276 | + # label='happybase-uncompressed cpu') | |
| 277 | + # plt.plot(range(len(data_size)), happybase_comp_cpu, marker='o', linestyle='--', | |
| 278 | + # label='happybase-compressed cpu') | |
| 279 | + # | |
| 280 | + # plt.xlabel("Data size") | |
| 281 | + # plt.ylabel("Time") | |
| 282 | + # plt.xticks(range(len(data_size)), data_size, size='small') | |
| 283 | + # plt.legend(loc=2) | |
| 284 | + # plt.show() | |
| 121 | 285 | |
| 286 | + plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') | |
| 287 | + plt.plot(data_size, dist_comp, marker='D', label='dist-compressed total') | |
| 288 | + plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') | |
| 289 | + plt.plot(data_size, happybase_comp_tot, marker='D', label='happybase-compressed total') | |
| 290 | + | |
| 291 | + plt.plot(data_size, happybase_uncomp_io, marker='o', linestyle='--', | |
| 292 | + label='happybase-uncompressed io') | |
| 293 | + plt.plot(data_size, happybase_comp_io, marker='D', linestyle='--', | |
| 294 | + label='happybase-compressed io') | |
| 295 | + plt.plot(data_size, happybase_uncomp_cpu, marker='o', linestyle='--', | |
| 296 | + label='happybase-uncompressed cpu') | |
| 297 | + plt.plot(data_size, happybase_comp_cpu, marker='D', linestyle='--', | |
| 298 | + label='happybase-compressed cpu') | |
| 299 | + | |
| 300 | + plt.xlabel("Data size") | |
| 301 | + plt.ylabel("Time") | |
| 302 | + plt.legend(loc=2) | |
| 303 | + plt.show() | |
| 122 | 304 | |
| 123 | 305 | |
| 306 | + # plt.subplot(2, 2, 1) | |
| 307 | + # plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') | |
| 308 | + # plt.plot(data_size, dist_comp, marker='o', label='dist-compressed total') | |
| 309 | + # # plt.title('Performance with(out) Compression') | |
| 310 | + # plt.ylabel("Time") | |
| 311 | + # plt.legend(loc=2) | |
| 312 | + # | |
| 313 | + # plt.subplot(2, 2, 2) | |
| 314 | + # plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') | |
| 315 | + # plt.plot(data_size, happybase_comp_tot, marker='o', label='happybase-compressed total') | |
| 316 | + # plt.legend(loc=2) | |
| 317 | + # | |
| 318 | + # plt.subplot(2, 2, 3) | |
| 319 | + # plt.plot(data_size, happybase_uncomp_io, marker='o', linestyle='--', | |
| 320 | + # label='happybase-uncompressed io') | |
| 321 | + # plt.plot(data_size, happybase_comp_io, marker='o', linestyle='--', | |
| 322 | + # label='happybase-compressed io') | |
| 323 | + # plt.ylabel("Time") | |
| 324 | + # plt.xlabel("Data size") | |
| 325 | + # plt.legend(loc=2) | |
| 326 | + # | |
| 327 | + # plt.subplot(2, 2, 4) | |
| 328 | + # plt.plot(data_size, happybase_uncomp_cpu, marker='o', linestyle='--', | |
| 329 | + # label='happybase-uncompressed cpu') | |
| 330 | + # plt.plot(data_size, happybase_comp_cpu, marker='o', linestyle='--', | |
| 331 | + # label='happybase-compressed cpu') | |
| 332 | + # plt.xlabel("Data size") | |
| 333 | + # plt.legend(loc=2) | |
| 334 | + # plt.show() | |
| 335 | + | |
| 336 | + # plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') | |
| 337 | + # plt.plot(data_size, dist_comp, marker='D', linestyle='--',label='dist-compressed total') | |
| 338 | + # plt.xlabel("Data size") | |
| 339 | + # plt.ylabel("Time(s)") | |
| 340 | + # plt.legend(loc=2) | |
| 341 | + # plt.show() | |
| 342 | + # | |
| 343 | + # plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') | |
| 344 | + # plt.plot(data_size, happybase_comp_tot, marker='D', linestyle='--',label='happybase-compressed total') | |
| 345 | + # plt.xlabel("Data size") | |
| 346 | + # plt.ylabel("Time(s)") | |
| 347 | + # plt.legend(loc=2) | |
| 348 | + # plt.show() | |
| 349 | + # | |
| 350 | + # plt.plot(data_size, happybase_uncomp_io, marker='o', | |
| 351 | + # label='happybase-uncompressed io') | |
| 352 | + # plt.plot(data_size, happybase_comp_io, marker='D', linestyle='--', | |
| 353 | + # label='happybase-compressed io') | |
| 354 | + # plt.xlabel("Data size") | |
| 355 | + # plt.ylabel("Time(s)") | |
| 356 | + # plt.legend(loc=2) | |
| 357 | + # plt.show() | |
| 358 | + # | |
| 359 | + # plt.plot(data_size, happybase_uncomp_cpu, marker='o', | |
| 360 | + # label='happybase-uncompressed cpu') | |
| 361 | + # plt.plot(data_size, happybase_comp_cpu, marker='D', linestyle='--', | |
| 362 | + # label='happybase-compressed cpu') | |
| 363 | + # | |
| 364 | + # plt.xlabel("Data size") | |
| 365 | + # plt.ylabel("Time(s)") | |
| 366 | + # plt.legend(loc=2) | |
| 367 | + # plt.show() | |
| 124 | 368 | |
| 125 | 369 | |
| 370 | +if __name__ == '__main__': | |
| 371 | + # anal_ILSVRC() | |
| 372 | + # anal_ILSVRC_Test() | |
| 373 | + # anal_0000() | |
| 374 | + # print timeit.timeit("anal_ILSVRC()", setup="from __main__ import anal_ILSVRC", number=1) | |
| 126 | 375 | |
| 127 | 376 | |
| 377 | + # pre_crop() | |
| 378 | + # plot_line() | |
| 379 | + anal_0000() | |
| 380 | + pass | ... | ... |
msteg/__init__.py
| ... | ... | @@ -7,7 +7,8 @@ from ..common import * |
| 7 | 7 | |
| 8 | 8 | __all__ = ['StegBase', 'sample_key'] |
| 9 | 9 | |
| 10 | -sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, | |
| 10 | +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, | |
| 11 | + 61908L, 63014L, | |
| 11 | 12 | 5908L, 59816L, 56765L] |
| 12 | 13 | |
| 13 | 14 | |
| ... | ... | @@ -38,7 +39,6 @@ class StegBase(object): |
| 38 | 39 | self.capacity = np.sum(self.cov_data != 0) - np.size(self.cov_data) / 64 |
| 39 | 40 | return self.cov_data |
| 40 | 41 | |
| 41 | - | |
| 42 | 42 | def _get_hid_data(self, src_hidden, frommem=False): |
| 43 | 43 | """ |
| 44 | 44 | Returnsthe secret data as byte sequence. |
| ... | ... | @@ -55,19 +55,20 @@ class StegBase(object): |
| 55 | 55 | self.hid_data = np.array(raw, dtype=np.uint8) |
| 56 | 56 | |
| 57 | 57 | if np.size(self.hid_data) * 8 > self.capacity: |
| 58 | - raise Exception("Cover image is too small to embed data.Cannot fit %d bits in %d NZ-DCT coefficients" % ( | |
| 59 | - np.size(self.hid_data) * 8, self.capacity)) | |
| 58 | + raise Exception( | |
| 59 | + "Cover image is too small to embed data.Cannot fit %d bits in %d NZ-DCT coefficients" % ( | |
| 60 | + np.size(self.hid_data) * 8, self.capacity)) | |
| 60 | 61 | return self.hid_data |
| 61 | 62 | |
| 62 | - | |
| 63 | - def _post_embed_actions(self, src_cover, src_hidden, tgt_stego): | |
| 63 | + def _post_embed_actions(self, src_cover, src_hidden, tgt_stego, frommem=False): | |
| 64 | 64 | """ |
| 65 | 65 | This function isn't named very accurately. It actually calls the |
| 66 | 66 | _raw_embed function in inherited classes. |
| 67 | 67 | """ |
| 68 | 68 | try: |
| 69 | 69 | cov_data = self._get_cov_data(src_cover) |
| 70 | - hid_data = self._get_hid_data(src_hidden) | |
| 70 | + # hid_data = self._get_hid_data(src_hidden) | |
| 71 | + hid_data = self._get_hid_data(src_hidden, frommem) | |
| 71 | 72 | # print hid_data.dtype,type(hid_data),hid_data.tolist() |
| 72 | 73 | cov_data, bits_cnt = self._raw_embed(cov_data, hid_data) |
| 73 | 74 | |
| ... | ... | @@ -130,7 +131,6 @@ class StegBase(object): |
| 130 | 131 | # print hid_data.dtype,type(hid_data),hid_data.tolist() |
| 131 | 132 | hid_data[4:].tofile(tgt_hidden) |
| 132 | 133 | |
| 133 | - | |
| 134 | 134 | self._display_rate('extract', self.capacity, bits_cnt) |
| 135 | 135 | |
| 136 | 136 | # self._display_stats("extracted", emb_size, |
| ... | ... | @@ -140,7 +140,6 @@ class StegBase(object): |
| 140 | 140 | print "Exception when extracting!" |
| 141 | 141 | raise |
| 142 | 142 | |
| 143 | - | |
| 144 | 143 | def _looks_like_jpeg(self, path): |
| 145 | 144 | try: |
| 146 | 145 | with open(path, 'r') as f: | ... | ... |
msteg/steganography/F3.py
| 1 | 1 | __author__ = 'chunk' |
| 2 | 2 | |
| 3 | - | |
| 4 | 3 | import math |
| 5 | 4 | import numpy as np |
| 6 | 5 | from .. import * |
| ... | ... | @@ -18,7 +17,7 @@ class F3(StegBase): |
| 18 | 17 | """ |
| 19 | 18 | StegBase.__init__(self) |
| 20 | 19 | |
| 21 | - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): | |
| 20 | + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): | |
| 22 | 21 | """ This method embeds arbitrary data into a cover image. |
| 23 | 22 | The cover image must be a JPEG. |
| 24 | 23 | |
| ... | ... | @@ -33,7 +32,7 @@ class F3(StegBase): |
| 33 | 32 | lossy compression. |
| 34 | 33 | """ |
| 35 | 34 | self.t0 = time.time() |
| 36 | - self._post_embed_actions(src_cover, src_hidden, tgt_stego) | |
| 35 | + self._post_embed_actions(src_cover, src_hidden, tgt_stego, frommem) | |
| 37 | 36 | |
| 38 | 37 | def extract_raw_data(self, src_steg, tgt_hidden): |
| 39 | 38 | """ This method extracts secret data from a stego image. It is |
| ... | ... | @@ -65,7 +64,7 @@ class F3(StegBase): |
| 65 | 64 | i += 1 |
| 66 | 65 | if i == hid_data.size: break |
| 67 | 66 | |
| 68 | - return cov_data,i | |
| 67 | + return cov_data, i | |
| 69 | 68 | |
| 70 | 69 | def _raw_extract(self, steg_data, num_bits): |
| 71 | 70 | """ |
| ... | ... | @@ -81,7 +80,7 @@ class F3(StegBase): |
| 81 | 80 | hid_data[j] = x & 1 |
| 82 | 81 | j = j + 1 |
| 83 | 82 | |
| 84 | - return hid_data,j | |
| 83 | + return hid_data, j | |
| 85 | 84 | |
| 86 | 85 | def __str__(self): |
| 87 | 86 | return 'F3' | ... | ... |
msteg/steganography/F4.py
| ... | ... | @@ -13,7 +13,7 @@ class F4(StegBase): |
| 13 | 13 | with the F3 algorithm and <i>extract_raw_data</i> to extract data |
| 14 | 14 | which was embedded previously. """ |
| 15 | 15 | |
| 16 | - def __init__(self, key=sample_key): | |
| 16 | + def __init__(self, key=None): | |
| 17 | 17 | """ |
| 18 | 18 | Constructor of the F3 class. |
| 19 | 19 | """ |
| ... | ... | @@ -27,15 +27,21 @@ class F4(StegBase): |
| 27 | 27 | |
| 28 | 28 | cov_data = self.cov_jpeg.getsignal(channel='Y') |
| 29 | 29 | self.cov_data = np.array(cov_data, dtype=np.int16) |
| 30 | + self.capacity = np.sum(self.cov_data != 0) - self.cov_data.size / 64 | |
| 31 | + | |
| 32 | + # signals = self.cov_jpeg.getsignal(channel='Y') | |
| 33 | + # self.signals = np.array(signals, dtype=np.int16) | |
| 34 | + # self.capacity = np.sum(self.signals != 0) | |
| 35 | + | |
| 30 | 36 | return self.cov_data |
| 31 | 37 | |
| 32 | - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): | |
| 38 | + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): | |
| 33 | 39 | |
| 34 | 40 | self.t0 = time.time() |
| 35 | 41 | |
| 36 | 42 | try: |
| 37 | 43 | cov_data = self._get_cov_data(src_cover) |
| 38 | - hid_data = self._get_hid_data(src_hidden) | |
| 44 | + hid_data = self._get_hid_data(src_hidden, frommem) | |
| 39 | 45 | # print hid_data.dtype,type(hid_data),hid_data.tolist() |
| 40 | 46 | |
| 41 | 47 | cov_data, bits_cnt = self._raw_embed(cov_data, hid_data) |
| ... | ... | @@ -47,8 +53,8 @@ class F4(StegBase): |
| 47 | 53 | self.cov_jpeg.setsignal(cov_data, channel='Y') |
| 48 | 54 | self.cov_jpeg.Jwrite(tgt_stego) |
| 49 | 55 | |
| 50 | - cov_bits = np.sum(cov_data != 0) - cov_data.size / 64 | |
| 51 | - self._display_rate(cov_bits, bits_cnt) | |
| 56 | + # cov_bits = np.sum(cov_data != 0) - cov_data.size / 64 | |
| 57 | + self._display_rate('embed', self.capacity, bits_cnt) | |
| 52 | 58 | |
| 53 | 59 | # # size_cov = os.path.getsize(tgt_stego) |
| 54 | 60 | # size_cov = np.size(cov_data) / 8 | ... | ... |
msteg/steganography/LSB.py
| ... | ... | @@ -12,13 +12,13 @@ class LSB(StegBase): |
| 12 | 12 | with the F3 algorithm and <i>extract_raw_data</i> to extract data |
| 13 | 13 | which was embedded previously. """ |
| 14 | 14 | |
| 15 | - def __init__(self): | |
| 15 | + def __init__(self, key=None): | |
| 16 | 16 | """ |
| 17 | 17 | Constructor of the F3 class. |
| 18 | 18 | """ |
| 19 | - StegBase.__init__(self) | |
| 19 | + StegBase.__init__(self, key) | |
| 20 | 20 | |
| 21 | - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): | |
| 21 | + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): | |
| 22 | 22 | """ This method embeds arbitrary data into a cover image. |
| 23 | 23 | The cover image must be a JPEG. |
| 24 | 24 | |
| ... | ... | @@ -33,7 +33,7 @@ class LSB(StegBase): |
| 33 | 33 | lossy compression. |
| 34 | 34 | """ |
| 35 | 35 | self.t0 = time.time() |
| 36 | - StegBase._post_embed_actions(self, src_cover, src_hidden, tgt_stego) | |
| 36 | + StegBase._post_embed_actions(self, src_cover, src_hidden, tgt_stego, frommem) | |
| 37 | 37 | |
| 38 | 38 | def extract_raw_data(self, src_steg, tgt_hidden): |
| 39 | 39 | """ This method extracts secret data from a stego image. It is |
| ... | ... | @@ -59,11 +59,12 @@ class LSB(StegBase): |
| 59 | 59 | if x == 0 or x == 1 or cnt % 64 == 0: continue |
| 60 | 60 | |
| 61 | 61 | m = (hid_data[i] & 1) |
| 62 | - x[...] = (x & 0xfffffffe) | m # '0xfffe' is enough, for elements are expected to be short integers. | |
| 62 | + x[...] = ( | |
| 63 | + x & 0xfffffffe) | m # '0xfffe' is enough, for elements are expected to be short integers. | |
| 63 | 64 | i += 1 |
| 64 | 65 | if i == hid_data.size: break |
| 65 | 66 | |
| 66 | - return cov_data | |
| 67 | + return cov_data, i | |
| 67 | 68 | |
| 68 | 69 | def _raw_extract(self, steg_data, num_bits): |
| 69 | 70 | """ | ... | ... |
797 KB
179 KB
235 KB
232 KB
210 KB
235 KB
test/test_jpeg.py
| 1 | 1 | __author__ = 'chunk' |
| 2 | 2 | |
| 3 | 3 | import numpy as np |
| 4 | +import matplotlib.pyplot as plt | |
| 5 | +import seaborn as sns | |
| 4 | 6 | from .. import mjpeg |
| 5 | 7 | from ..mjpeg import base |
| 8 | +from ..msteg.steganography import LSB, F3, F4, F5 | |
| 6 | 9 | |
| 7 | 10 | from ..common import * |
| 8 | 11 | |
| ... | ... | @@ -17,9 +20,14 @@ sample = [[7, 12, 14, -12, 1, 0, -1, 0], |
| 17 | 20 | [0, 0, 0, 0, 0, 0, 0, 0], |
| 18 | 21 | [0, 0, 0, 0, 0, 0, 0, 0]] |
| 19 | 22 | |
| 20 | -sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, | |
| 23 | +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, | |
| 24 | + 61908L, 63014L, | |
| 21 | 25 | 5908L, 59816L, 56765L] |
| 22 | 26 | |
| 27 | +# plt.ticklabel_format(style='sci', axis='both', scilimits=(1, 4)) | |
| 28 | + | |
| 29 | +plt.ticklabel_format(style='sci', axis='both') | |
| 30 | + | |
| 23 | 31 | package_dir = os.path.dirname(os.path.abspath(__file__)) |
| 24 | 32 | |
| 25 | 33 | |
| ... | ... | @@ -33,7 +41,7 @@ def test_setblocks(): |
| 33 | 41 | |
| 34 | 42 | imb.setCoefMatrix(np.array([[0] * 800 for i in range(600)]), channel='Y') |
| 35 | 43 | |
| 36 | - block = imb.getCoefBlock(channel='Y', loc=(-1, 2)) | |
| 44 | + block = imb.getCoefBlock(channe99l='Y', loc=(-1, 2)) | |
| 37 | 45 | print block |
| 38 | 46 | |
| 39 | 47 | imb.Jwrite("res/test4.jpg") |
| ... | ... | @@ -165,7 +173,37 @@ def test_jpeg(): |
| 165 | 173 | """ |
| 166 | 174 | |
| 167 | 175 | |
| 176 | +def test_hist(): | |
| 177 | + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/high/pic3_orig.jpg"), key=sample_key) | |
| 178 | + print ima.getQuality() | |
| 179 | + print ima.getCapacity('All') | |
| 180 | + | |
| 181 | + capacity = ima.getCapacity() | |
| 182 | + print capacity | |
| 183 | + rate = 0.65 | |
| 184 | + hidden = np.random.bytes(int(int(capacity) * rate) / 8) | |
| 185 | + steger = F5.F5(sample_key, 1) | |
| 186 | + steger2 = F4.F4(key=None) | |
| 187 | + steger3 = LSB.LSB(key=None) | |
| 188 | + embed_rate = steger3.embed_raw_data(os.path.join(package_dir, "../res/high/pic3_orig.jpg"), | |
| 189 | + hidden, | |
| 190 | + os.path.join(package_dir, "../res/high/pic3_dest.jpg"), | |
| 191 | + frommem=True) | |
| 192 | + # | |
| 193 | + print embed_rate | |
| 194 | + | |
| 195 | + imb = mjpeg.Jpeg(os.path.join(package_dir, "../res/high/pic3_dest.jpg"), key=sample_key) | |
| 196 | + print imb.getQuality() | |
| 197 | + print imb.getCapacity('All') | |
| 168 | 198 | |
| 199 | + A = imb.rawsignal().tolist() | |
| 200 | + E = [i for i in range(-8, 10)] | |
| 201 | + plt.hist(A, E, histtype='bar', rwidth=0.8, align='left') | |
| 202 | + plt.xlabel("JPEG coefficients after quantisation") | |
| 203 | + plt.ylabel("Frequency") | |
| 204 | + plt.xticks([i for i in range(-8, 9)]) | |
| 205 | + plt.ylim(ymax=300000) | |
| 206 | + plt.show() | |
| 169 | 207 | |
| 170 | 208 | |
| 171 | 209 | if __name__ == '__main__': |
| ... | ... | @@ -214,14 +252,3 @@ if __name__ == '__main__': |
| 214 | 252 | # sample = np.array(sample)[mmask] |
| 215 | 253 | # print np.hstack([[],sample]) |
| 216 | 254 | pass |
| 217 | - | |
| 218 | - | |
| 219 | - | |
| 220 | - | |
| 221 | - | |
| 222 | - | |
| 223 | - | |
| 224 | - | |
| 225 | - | |
| 226 | - | |
| 227 | - | ... | ... |