From 95f76ce882085a85eb304d47d0cc33104b5bb1be Mon Sep 17 00:00:00 2001 From: Chunk Date: Mon, 15 Jun 2015 17:40:22 +0800 Subject: [PATCH] theis finished.论文查重2.1 ( ̄ˇ ̄) --- mdata/ANALYSIS.py | 281 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- msteg/__init__.py | 17 ++++++++--------- msteg/steganography/F3.py | 9 ++++----- msteg/steganography/F4.py | 16 +++++++++++----- msteg/steganography/LSB.py | 13 +++++++------ res/high/pic1.jpg | Bin 0 -> 815682 bytes res/high/pic2.jpg | Bin 0 -> 183616 bytes res/high/pic3.jpg | Bin 0 -> 240399 bytes res/high/pic3_dest.jpg | Bin 0 -> 237587 bytes res/high/pic3_f5_1_0.8.jpg | Bin 0 -> 215376 bytes res/high/pic3_orig.jpg | Bin 0 -> 240399 bytes test/test_jpeg.py | 53 ++++++++++++++++++++++++++++++++++++++++------------- 12 files changed, 337 insertions(+), 52 deletions(-) create mode 100644 res/high/pic1.jpg create mode 100644 res/high/pic2.jpg create mode 100644 res/high/pic3.jpg create mode 100644 res/high/pic3_dest.jpg create mode 100644 res/high/pic3_f5_1_0.8.jpg create mode 100644 res/high/pic3_orig.jpg diff --git a/mdata/ANALYSIS.py b/mdata/ANALYSIS.py index 739a712..4668b44 100644 --- a/mdata/ANALYSIS.py +++ b/mdata/ANALYSIS.py @@ -9,14 +9,27 @@ import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns +import numpy as np +import matplotlib.pyplot as plt +import seaborn as sns +from .. import mjpeg +from ..mjpeg import base +from ..msteg.steganography import LSB, F3, F4, F5 + np.random.seed(sum(map(ord, "whoami"))) -plt.ticklabel_format(style='sci', axis='both', scilimits=(1, 4)) + +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, + 61908L, 63014L, 5908L, 59816L, 56765L] + +# plt.ticklabel_format(style='sci', axis='both', scilimits=(0, 0)) +plt.ticklabel_format(style='sci', axis='both') package_dir = os.path.dirname(os.path.abspath(__file__)) def anal_ILSVRC(): - df_ILS = pd.read_csv('../res/file-tag.tsv', names=['hash', 'width', 'height', 'size', 'quality'], sep='\t') + df_ILS = pd.read_csv('../res/file-tag.tsv', + names=['hash', 'width', 'height', 'size', 'quality'], sep='\t') print df_ILS[df_ILS.size < 2000000] print df_ILS.describe() # df_ILS.boxplot(column='size') @@ -68,7 +81,8 @@ def anal_ILSVRC(): def anal_ILSVRC_Test(): - df_ILS_T = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','class'], sep='\t') + df_ILS_T = pd.read_csv('../res/file-tag-test.tsv', + names=['hash', 'width', 'height', 'size', 'quality', 'class'], sep='\t') print df_ILS_T print df_ILS_T.size.describe() @@ -80,23 +94,35 @@ def anal_ILSVRC_Test(): df_ILS_T['class2'] = np.zeros(length, np.int32) df_ILS_T.to_csv('../res/file-tag-test.tsv', header=False, index=False, sep='\t') + def anal_0000(): - df_ILS = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','chosen','class'], sep='\t') + df_ILS = pd.read_csv(os.path.join(package_dir, '../res/file-tag-test.tsv'), + names=['hash', 'width', 'height', 'size', 'quality', 'chosen', 'class'], + sep='\t') length = df_ILS.shape[0] print df_ILS.size.describe() print df_ILS.size.order().iloc[map(lambda x: x * length, [1.0 / 3, 2.0 / 3, 0.9999])] + print df_ILS.size[df_ILS.size == 166500].count() / 4592.0 + print df_ILS.size[df_ILS.size == 187500].count() / 4592.0 + print df_ILS.size[df_ILS.size == 250000].count() / 4592.0 + print df_ILS.size[df_ILS.size <= 166500].count() print df_ILS.size[(df_ILS['size'] > 166500) & (df_ILS['size'] <= 187500)].count() print df_ILS.size[df_ILS.size > 187500].count() - df_ILS.hist(column='size',bins=100) + plt.ticklabel_format(style='sci', axis='both') + df_ILS.hist(column='size', bins=100) + plt.title('') + plt.xlabel("Image size") + plt.ylabel("Frequency") plt.show() - def pre_crop(): - df_ILS = pd.read_csv('../res/file-tag-test.tsv', names=['hash', 'width', 'height', 'size', 'quality','chosen','class'], sep='\t') + df_ILS = pd.read_csv(os.path.join(package_dir, '../res/file-tag-test.tsv'), + names=['hash', 'width', 'height', 'size', 'quality', 'chosen', 'class'], + sep='\t') print df_ILS.shape print df_ILS[(df_ILS['width'] >= 300) & (df_ILS['height'] >= 300)].shape @@ -105,23 +131,250 @@ def pre_crop(): # 400x400 932 0.202 +def plot_hist(): + dat_performance = np.array([ + [100, 0.583396, 30.847788, 57.884814, 89.315998, 1.471087, 29.364628, 9.114235, 10.585322, + 39.94995, 2.235697366], + [200, 1.147411, 62.815709, 118.217859, 182.180979, 3.008692, 37.920278, 19.589578, 22.59827, + 60.518548, 3.010332948], + [500, 2.763806, 162.806317, 299.778606, 465.348729, 6.81705, 88.291989, 73.446282, + 80.263332, 168.555321, 2.760807112], + [1000, 6.372794, 329.023151, 600.438977, 935.834922, 15.644418, 159.951099, 186.335413, + 201.979831, 361.93093, 2.585672692], + [2000, 14.960961, 679.357936, 1256.341536, 1950.660433, 31.699596, 313.154748, 387.063702, + 418.763298, 731.918046, 2.665135043], + [5000, 39.880657, 1652.537536, 3067.98039, 4760.398583, 73.070203, 694.454719, 898.458633, + 971.528836, 1665.983555, 2.857410308]]) + + dat_performance = np.transpose(dat_performance) + data_size, serial_tot, spark_io, spark_proc, spark_tot = dat_performance[0], dat_performance[4], \ + dat_performance[8], dat_performance[6], \ + dat_performance[9] + + data_size = data_size.astype(int) + A = [spark_io, spark_proc] + E = np.arange(len(data_size)) + bar_width = 0.5 + # plt.bar(E, spark_io, width=bar_width) + # plt.bar(E, spark_proc, color='#e74c3c', width=bar_width, bottom=spark_io) + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.xticks(E + bar_width / 2, data_size) + # # plt.xticks(range(len(data_size)), data_size, size='small') + # # plt.ylim(ymax=300000) + # plt.show() + + # mpl.rcParams.update({'font.size': 5}) + fig, ax = plt.subplots() + rects1 = ax.bar(E, spark_io, bar_width) + rects2 = ax.bar(E, spark_proc, bar_width, color='#e74c3c', bottom=spark_io) -if __name__ == '__main__': - # anal_ILSVRC() - # anal_ILSVRC_Test() - # anal_0000() - # print timeit.timeit("anal_ILSVRC()", setup="from __main__ import anal_ILSVRC", number=1) + # add some text for labels, title and axes ticks + plt.xlabel("Data size") + ax.set_ylabel('Time(s)') + # ax.set_title('IO ratio') + ax.set_xticks(E + bar_width / 2) + ax.set_xticklabels(data_size) + ax.legend((rects1[0], rects2[0]), ('IO', 'CPU'), loc=2) - pre_crop() - pass + height1 = [rect.get_height() for rect in rects1] + height2 = [rect.get_height() for rect in rects2] + for i in range(len(rects1)): + height = rects1[i].get_height() + rects2[i].get_height() + ax.text(rects1[i].get_x() + rects1[i].get_width() / 2, 1.005 * height, '%d%%' % + int((100 * 1.0*height1[i]/height)), + ha='center', va='bottom') + + # height1 = [rect.get_height() for rect in rects1] + # height2 = [rect.get_height() for rect in rects2] + # for i in range(len(rects1)): + # ax.text(rects1[i].get_x() + rects1[i].get_width() / 2, 0.5 * height1[i], '%f' % (0.1 * + # height1[ + # i] / + # height2[ + # i]), + # ha='center', va='bottom') + + + plt.show() + + +def plot_line_performance(): + # performance + dat_performance = np.array([ + [100, 0.583396, 30.847788, 57.884814, 89.315998, 1.471087, 29.364628, 9.114235, 10.585322, + 39.94995, 2.235697366], + [200, 1.147411, 62.815709, 118.217859, 182.180979, 3.008692, 37.920278, 19.589578, 22.59827, + 60.518548, 3.010332948], + [500, 2.763806, 162.806317, 299.778606, 465.348729, 6.81705, 88.291989, 73.446282, + 80.263332, 168.555321, 2.760807112], + [1000, 6.372794, 329.023151, 600.438977, 935.834922, 15.644418, 159.951099, 186.335413, + 201.979831, 361.93093, 2.585672692], + [2000, 14.960961, 679.357936, 1256.341536, 1950.660433, 31.699596, 313.154748, 387.063702, + 418.763298, 731.918046, 2.665135043], + [5000, 39.880657, 1652.537536, 3067.98039, 4760.398583, 73.070203, 694.454719, 898.458633, + 971.528836, 1665.983555, 2.857410308]]) + + dat_performance = np.transpose(dat_performance) + data_size, serial_tot, spark_io, spark_proc, spark_tot = dat_performance[0], dat_performance[4], \ + dat_performance[8], dat_performance[6], \ + dat_performance[9] + + # sns.set_style("white") + # data_size = data_size.astype(int) + # plt.plot(range(len(data_size)), serial_tot, marker='o', label='serial total') + # plt.plot(range(len(data_size)), spark_tot, marker='o', linestyle='--', label='spark total') + # plt.plot(range(len(data_size)), spark_io, marker='o', linestyle=':', label='spark io') + # plt.plot(range(len(data_size)), spark_proc, marker='o', linestyle='-.', label='spark proc') + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.xticks(range(len(data_size)), data_size, size='small') + # plt.legend(loc=2) + # plt.show() + + plt.plot(data_size, serial_tot, marker='o', label='serial total') + plt.plot(data_size, spark_tot, marker='o', linestyle='--', label='spark total') + plt.plot(data_size, spark_io, marker='o', linestyle=':', label='spark io') + plt.plot(data_size, spark_proc, marker='o', linestyle='-.', label='spark proc') + plt.xlabel("Data size") + plt.ylabel("Time(s)") + plt.legend(loc=2) + plt.show() +def plot_line_io(): + # io + dat_io = np.array([ + [100, 10.585322, 29.364628, 39.94995, 10.286684, 27.079774, 37.366458, 49.995647, + 55.280739], + [200, 22.59827, 37.920278, 60.518548, 22.731275, 38.491461, 61.222736, 76.258928, + 83.836657], + [500, 80.263332, 88.291989, 168.555321, 64.610839, 88.241193, 152.852032, 177.039349, + 143.524813], + [1000, 201.979831, 159.951099, 361.93093, 172.359455, 158.694248, 331.053703, 467.126756, + 315.578952], + [2000, 418.763298, 313.154748, 731.918046, 390.990209, 313.085707, 704.075916, 802.138669, + 734.133909], + [5000, 971.528836, 694.454719, 1665.983555, 898.468232, 717.603061, 1616.071293, + 1860.610954, 1677.044038]]) + + dat_io = np.transpose(dat_io) + 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 + # data_size = data_size.astype(int) + # plt.plot(range(len(data_size)), dist_uncomp, marker='o', label='dist-uncompressed total') + # plt.plot(range(len(data_size)), dist_comp, marker='o', label='dist-compressed total') + # plt.plot(range(len(data_size)), happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') + # plt.plot(range(len(data_size)), happybase_comp_tot, marker='o', label='happybase-compressed total') + # + # plt.plot(range(len(data_size)), happybase_uncomp_io, marker='o', linestyle='--', + # label='happybase-uncompressed io') + # plt.plot(range(len(data_size)), happybase_comp_io, marker='o', linestyle='--', + # label='happybase-compressed io') + # plt.plot(range(len(data_size)), happybase_uncomp_cpu, marker='o', linestyle='--', + # label='happybase-uncompressed cpu') + # plt.plot(range(len(data_size)), happybase_comp_cpu, marker='o', linestyle='--', + # label='happybase-compressed cpu') + # + # plt.xlabel("Data size") + # plt.ylabel("Time") + # plt.xticks(range(len(data_size)), data_size, size='small') + # plt.legend(loc=2) + # plt.show() + plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') + plt.plot(data_size, dist_comp, marker='D', label='dist-compressed total') + plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') + plt.plot(data_size, happybase_comp_tot, marker='D', label='happybase-compressed total') + + plt.plot(data_size, happybase_uncomp_io, marker='o', linestyle='--', + label='happybase-uncompressed io') + plt.plot(data_size, happybase_comp_io, marker='D', linestyle='--', + label='happybase-compressed io') + plt.plot(data_size, happybase_uncomp_cpu, marker='o', linestyle='--', + label='happybase-uncompressed cpu') + plt.plot(data_size, happybase_comp_cpu, marker='D', linestyle='--', + label='happybase-compressed cpu') + + plt.xlabel("Data size") + plt.ylabel("Time") + plt.legend(loc=2) + plt.show() + # plt.subplot(2, 2, 1) + # plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') + # plt.plot(data_size, dist_comp, marker='o', label='dist-compressed total') + # # plt.title('Performance with(out) Compression') + # plt.ylabel("Time") + # plt.legend(loc=2) + # + # plt.subplot(2, 2, 2) + # plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') + # plt.plot(data_size, happybase_comp_tot, marker='o', label='happybase-compressed total') + # plt.legend(loc=2) + # + # plt.subplot(2, 2, 3) + # plt.plot(data_size, happybase_uncomp_io, marker='o', linestyle='--', + # label='happybase-uncompressed io') + # plt.plot(data_size, happybase_comp_io, marker='o', linestyle='--', + # label='happybase-compressed io') + # plt.ylabel("Time") + # plt.xlabel("Data size") + # plt.legend(loc=2) + # + # plt.subplot(2, 2, 4) + # plt.plot(data_size, happybase_uncomp_cpu, marker='o', linestyle='--', + # label='happybase-uncompressed cpu') + # plt.plot(data_size, happybase_comp_cpu, marker='o', linestyle='--', + # label='happybase-compressed cpu') + # plt.xlabel("Data size") + # plt.legend(loc=2) + # plt.show() + + # plt.plot(data_size, dist_uncomp, marker='o', label='dist-uncompressed total') + # plt.plot(data_size, dist_comp, marker='D', linestyle='--',label='dist-compressed total') + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.legend(loc=2) + # plt.show() + # + # plt.plot(data_size, happybase_uncomp_tot, marker='o', label='happybase-uncompressed total') + # plt.plot(data_size, happybase_comp_tot, marker='D', linestyle='--',label='happybase-compressed total') + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.legend(loc=2) + # plt.show() + # + # plt.plot(data_size, happybase_uncomp_io, marker='o', + # label='happybase-uncompressed io') + # plt.plot(data_size, happybase_comp_io, marker='D', linestyle='--', + # label='happybase-compressed io') + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.legend(loc=2) + # plt.show() + # + # plt.plot(data_size, happybase_uncomp_cpu, marker='o', + # label='happybase-uncompressed cpu') + # plt.plot(data_size, happybase_comp_cpu, marker='D', linestyle='--', + # label='happybase-compressed cpu') + # + # plt.xlabel("Data size") + # plt.ylabel("Time(s)") + # plt.legend(loc=2) + # plt.show() +if __name__ == '__main__': + # anal_ILSVRC() + # anal_ILSVRC_Test() + # anal_0000() + # print timeit.timeit("anal_ILSVRC()", setup="from __main__ import anal_ILSVRC", number=1) + # pre_crop() + # plot_line() + anal_0000() + pass diff --git a/msteg/__init__.py b/msteg/__init__.py index 77cd137..e184b09 100644 --- a/msteg/__init__.py +++ b/msteg/__init__.py @@ -7,7 +7,8 @@ from ..common import * __all__ = ['StegBase', 'sample_key'] -sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, + 61908L, 63014L, 5908L, 59816L, 56765L] @@ -38,7 +39,6 @@ class StegBase(object): self.capacity = np.sum(self.cov_data != 0) - np.size(self.cov_data) / 64 return self.cov_data - def _get_hid_data(self, src_hidden, frommem=False): """ Returnsthe secret data as byte sequence. @@ -55,19 +55,20 @@ class StegBase(object): self.hid_data = np.array(raw, dtype=np.uint8) if np.size(self.hid_data) * 8 > self.capacity: - raise Exception("Cover image is too small to embed data.Cannot fit %d bits in %d NZ-DCT coefficients" % ( - np.size(self.hid_data) * 8, self.capacity)) + raise Exception( + "Cover image is too small to embed data.Cannot fit %d bits in %d NZ-DCT coefficients" % ( + np.size(self.hid_data) * 8, self.capacity)) return self.hid_data - - def _post_embed_actions(self, src_cover, src_hidden, tgt_stego): + def _post_embed_actions(self, src_cover, src_hidden, tgt_stego, frommem=False): """ This function isn't named very accurately. It actually calls the _raw_embed function in inherited classes. """ try: cov_data = self._get_cov_data(src_cover) - hid_data = self._get_hid_data(src_hidden) + # hid_data = self._get_hid_data(src_hidden) + hid_data = self._get_hid_data(src_hidden, frommem) # print hid_data.dtype,type(hid_data),hid_data.tolist() cov_data, bits_cnt = self._raw_embed(cov_data, hid_data) @@ -130,7 +131,6 @@ class StegBase(object): # print hid_data.dtype,type(hid_data),hid_data.tolist() hid_data[4:].tofile(tgt_hidden) - self._display_rate('extract', self.capacity, bits_cnt) # self._display_stats("extracted", emb_size, @@ -140,7 +140,6 @@ class StegBase(object): print "Exception when extracting!" raise - def _looks_like_jpeg(self, path): try: with open(path, 'r') as f: diff --git a/msteg/steganography/F3.py b/msteg/steganography/F3.py index dd3711d..8ea0bc1 100644 --- a/msteg/steganography/F3.py +++ b/msteg/steganography/F3.py @@ -1,6 +1,5 @@ __author__ = 'chunk' - import math import numpy as np from .. import * @@ -18,7 +17,7 @@ class F3(StegBase): """ StegBase.__init__(self) - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): """ This method embeds arbitrary data into a cover image. The cover image must be a JPEG. @@ -33,7 +32,7 @@ class F3(StegBase): lossy compression. """ self.t0 = time.time() - self._post_embed_actions(src_cover, src_hidden, tgt_stego) + self._post_embed_actions(src_cover, src_hidden, tgt_stego, frommem) def extract_raw_data(self, src_steg, tgt_hidden): """ This method extracts secret data from a stego image. It is @@ -65,7 +64,7 @@ class F3(StegBase): i += 1 if i == hid_data.size: break - return cov_data,i + return cov_data, i def _raw_extract(self, steg_data, num_bits): """ @@ -81,7 +80,7 @@ class F3(StegBase): hid_data[j] = x & 1 j = j + 1 - return hid_data,j + return hid_data, j def __str__(self): return 'F3' diff --git a/msteg/steganography/F4.py b/msteg/steganography/F4.py index 9ad5c5b..0153233 100644 --- a/msteg/steganography/F4.py +++ b/msteg/steganography/F4.py @@ -13,7 +13,7 @@ class F4(StegBase): with the F3 algorithm and extract_raw_data to extract data which was embedded previously. """ - def __init__(self, key=sample_key): + def __init__(self, key=None): """ Constructor of the F3 class. """ @@ -27,15 +27,21 @@ class F4(StegBase): cov_data = self.cov_jpeg.getsignal(channel='Y') self.cov_data = np.array(cov_data, dtype=np.int16) + self.capacity = np.sum(self.cov_data != 0) - self.cov_data.size / 64 + + # signals = self.cov_jpeg.getsignal(channel='Y') + # self.signals = np.array(signals, dtype=np.int16) + # self.capacity = np.sum(self.signals != 0) + return self.cov_data - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): self.t0 = time.time() try: cov_data = self._get_cov_data(src_cover) - hid_data = self._get_hid_data(src_hidden) + hid_data = self._get_hid_data(src_hidden, frommem) # print hid_data.dtype,type(hid_data),hid_data.tolist() cov_data, bits_cnt = self._raw_embed(cov_data, hid_data) @@ -47,8 +53,8 @@ class F4(StegBase): self.cov_jpeg.setsignal(cov_data, channel='Y') self.cov_jpeg.Jwrite(tgt_stego) - cov_bits = np.sum(cov_data != 0) - cov_data.size / 64 - self._display_rate(cov_bits, bits_cnt) + # cov_bits = np.sum(cov_data != 0) - cov_data.size / 64 + self._display_rate('embed', self.capacity, bits_cnt) # # size_cov = os.path.getsize(tgt_stego) # size_cov = np.size(cov_data) / 8 diff --git a/msteg/steganography/LSB.py b/msteg/steganography/LSB.py index e5fd118..4f5f40e 100644 --- a/msteg/steganography/LSB.py +++ b/msteg/steganography/LSB.py @@ -12,13 +12,13 @@ class LSB(StegBase): with the F3 algorithm and extract_raw_data to extract data which was embedded previously. """ - def __init__(self): + def __init__(self, key=None): """ Constructor of the F3 class. """ - StegBase.__init__(self) + StegBase.__init__(self, key) - def embed_raw_data(self, src_cover, src_hidden, tgt_stego): + def embed_raw_data(self, src_cover, src_hidden, tgt_stego, frommem=False): """ This method embeds arbitrary data into a cover image. The cover image must be a JPEG. @@ -33,7 +33,7 @@ class LSB(StegBase): lossy compression. """ self.t0 = time.time() - StegBase._post_embed_actions(self, src_cover, src_hidden, tgt_stego) + StegBase._post_embed_actions(self, src_cover, src_hidden, tgt_stego, frommem) def extract_raw_data(self, src_steg, tgt_hidden): """ This method extracts secret data from a stego image. It is @@ -59,11 +59,12 @@ class LSB(StegBase): if x == 0 or x == 1 or cnt % 64 == 0: continue m = (hid_data[i] & 1) - x[...] = (x & 0xfffffffe) | m # '0xfffe' is enough, for elements are expected to be short integers. + x[...] = ( + x & 0xfffffffe) | m # '0xfffe' is enough, for elements are expected to be short integers. i += 1 if i == hid_data.size: break - return cov_data + return cov_data, i def _raw_extract(self, steg_data, num_bits): """ diff --git a/res/high/pic1.jpg b/res/high/pic1.jpg new file mode 100644 index 0000000..12c06e5 Binary files /dev/null and b/res/high/pic1.jpg differ diff --git a/res/high/pic2.jpg b/res/high/pic2.jpg new file mode 100644 index 0000000..0b89aee Binary files /dev/null and b/res/high/pic2.jpg differ diff --git a/res/high/pic3.jpg b/res/high/pic3.jpg new file mode 100644 index 0000000..82d9205 Binary files /dev/null and b/res/high/pic3.jpg differ diff --git a/res/high/pic3_dest.jpg b/res/high/pic3_dest.jpg new file mode 100644 index 0000000..c4ea6a4 Binary files /dev/null and b/res/high/pic3_dest.jpg differ diff --git a/res/high/pic3_f5_1_0.8.jpg b/res/high/pic3_f5_1_0.8.jpg new file mode 100644 index 0000000..2a692a7 Binary files /dev/null and b/res/high/pic3_f5_1_0.8.jpg differ diff --git a/res/high/pic3_orig.jpg b/res/high/pic3_orig.jpg new file mode 100644 index 0000000..82d9205 Binary files /dev/null and b/res/high/pic3_orig.jpg differ diff --git a/test/test_jpeg.py b/test/test_jpeg.py index 777cc72..6273832 100644 --- a/test/test_jpeg.py +++ b/test/test_jpeg.py @@ -1,8 +1,11 @@ __author__ = 'chunk' import numpy as np +import matplotlib.pyplot as plt +import seaborn as sns from .. import mjpeg from ..mjpeg import base +from ..msteg.steganography import LSB, F3, F4, F5 from ..common import * @@ -17,9 +20,14 @@ sample = [[7, 12, 14, -12, 1, 0, -1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] -sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, +sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, + 61908L, 63014L, 5908L, 59816L, 56765L] +# plt.ticklabel_format(style='sci', axis='both', scilimits=(1, 4)) + +plt.ticklabel_format(style='sci', axis='both') + package_dir = os.path.dirname(os.path.abspath(__file__)) @@ -33,7 +41,7 @@ def test_setblocks(): imb.setCoefMatrix(np.array([[0] * 800 for i in range(600)]), channel='Y') - block = imb.getCoefBlock(channel='Y', loc=(-1, 2)) + block = imb.getCoefBlock(channe99l='Y', loc=(-1, 2)) print block imb.Jwrite("res/test4.jpg") @@ -165,7 +173,37 @@ def test_jpeg(): """ +def test_hist(): + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/high/pic3_orig.jpg"), key=sample_key) + print ima.getQuality() + print ima.getCapacity('All') + + capacity = ima.getCapacity() + print capacity + rate = 0.65 + hidden = np.random.bytes(int(int(capacity) * rate) / 8) + steger = F5.F5(sample_key, 1) + steger2 = F4.F4(key=None) + steger3 = LSB.LSB(key=None) + embed_rate = steger3.embed_raw_data(os.path.join(package_dir, "../res/high/pic3_orig.jpg"), + hidden, + os.path.join(package_dir, "../res/high/pic3_dest.jpg"), + frommem=True) + # + print embed_rate + + imb = mjpeg.Jpeg(os.path.join(package_dir, "../res/high/pic3_dest.jpg"), key=sample_key) + print imb.getQuality() + print imb.getCapacity('All') + A = imb.rawsignal().tolist() + E = [i for i in range(-8, 10)] + plt.hist(A, E, histtype='bar', rwidth=0.8, align='left') + plt.xlabel("JPEG coefficients after quantisation") + plt.ylabel("Frequency") + plt.xticks([i for i in range(-8, 9)]) + plt.ylim(ymax=300000) + plt.show() if __name__ == '__main__': @@ -214,14 +252,3 @@ if __name__ == '__main__': # sample = np.array(sample)[mmask] # print np.hstack([[],sample]) pass - - - - - - - - - - - -- libgit2 0.21.2