diff --git a/mjpeg/__init__.py b/mjpeg/__init__.py index 53d3f4c..dc745df 100644 --- a/mjpeg/__init__.py +++ b/mjpeg/__init__.py @@ -257,9 +257,12 @@ class Jpeg(Jsteg): colour channel (as a 4-D tensor: (v,h,row,col)). """ if channel == "All": - return np.array([ - [np.hsplit(arr, arr.shape[1] / 8) for arr in np.vsplit(compMat, compMat.shape[0] / 8)] for compMat in - self.coef_arrays]) + # return [ + # [np.hsplit(arr, arr.shape[1] / 8) for arr in np.vsplit(compMat, compMat.shape[0] / 8)] for compMat in + # self.coef_arrays] + return [ + np.array([np.hsplit(arr, arr.shape[1] / 8) for compMat in + self.coef_arrays for arr in np.vsplit(compMat, compMat.shape[0] / 8)])] compMat = self.getCoefMatrix(channel) return np.array([np.hsplit(arr, arr.shape[1] / 8) for arr in np.vsplit(compMat, compMat.shape[0] / 8)]) @@ -295,11 +298,19 @@ class Jpeg(Jsteg): return self.image_width, self.image_height def getCapacity(self, channel="All"): - blocks = self.getCoefBlocks(channel) - print blocks.shape - return (np.sum(blocks[0] != 0) - np.size(blocks[0]) / 64) + (np.sum(blocks[1] != 0) - np.size( - blocks[1]) / 64) / 4 + (np.sum(blocks[2] != 0) - np.size(blocks[2]) / 64) / 4 - # return np.sum(np.array(self.coef_arrays)!=0) - np.size(self.coef_arrays) / 64 + # blocks = self.getCoefBlocks(channel) + # print blocks.shape + # return (np.sum(blocks[0] != 0) - np.size(blocks[0]) / 64) + (np.sum(blocks[1] != 0) - np.size( + # blocks[1]) / 64) / 4 + (np.sum(blocks[2] != 0) - np.size(blocks[2]) / 64) / 4 + capacity = 0 + if channel == 'All': + for blocks in self.getCoefBlocks(channel): + print blocks + capacity += (np.sum(np.array(blocks) != 0) - np.size(blocks) / 64) + else: + blocks = self.getCoefBlocks(channel) + capacity += (np.sum(np.array(blocks) != 0) - np.size(blocks) / 64) + return capacity def getQuality(self): @@ -359,28 +370,6 @@ class Jpeg(Jsteg): # assert max( abs(S).flatten() ) <=128, "Image colours out of range" return (S + 128 ).astype(np.uint8) - # Complete, general decompression is not yet implemented:: - - def getimage(self): - """ - Decompress the image and a PIL Image object. - """ - - # Probably better to use a numpy image/array. - - raise NotImplementedError, "Decompression is not yet implemented" - - # We miss the routines for upsampling and adjusting the size - - L = len(self.coef_arrays) - im = [] - for i in range(L): - C = self.coef_arrays[i] - if C != None: - Q = self.quant_tables[self.comp_info[i]["quant_tbl_no"]] - im.append(ibdct(dequantise(C, Q))) - return Image.fromarray(im) - # Calibration # ----------- diff --git a/msteg/__init__.py b/msteg/__init__.py index b9266f7..89afe96 100644 --- a/msteg/__init__.py +++ b/msteg/__init__.py @@ -2,8 +2,9 @@ __author__ = 'chunk' import numpy as np -from ..mjpeg import Jpeg from ..common import * +from ..mjpeg import Jpeg + __all__ = ['StegBase', 'sample_key'] @@ -33,7 +34,7 @@ class StegBase(object): """ self.cov_jpeg = Jpeg(img_path) self.key = self.cov_jpeg.getkey() - self.cov_data = self.cov_jpeg.getCoefBlocks() + self.cov_data = self.cov_jpeg.getCoefBlocks('All') return self.cov_data @@ -49,7 +50,7 @@ class StegBase(object): self.hid_data = np.array(raw, dtype=np.uint8) if np.size(self.hid_data) * 8 > np.size(self.cov_data): - raise Exception("Cover image is too small to embed data.Cannot fit %d bits in %d DCT coefficients" % ( + print("[WARN] Cover image is too small to embed data.Cannot fit %d bits in %d DCT coefficients" % ( np.size(self.hid_data) * 8, np.size(self.cov_data))) return self.hid_data diff --git a/res/166500/221379062154e32d0efa5cce32f1b.jpg b/res/166500/221379062154e32d0efa5cce32f1b.jpg new file mode 100644 index 0000000..e964d3d Binary files /dev/null and b/res/166500/221379062154e32d0efa5cce32f1b.jpg differ diff --git a/res/166500/55df71faed43b37a8ac242120a72d.jpg b/res/166500/55df71faed43b37a8ac242120a72d.jpg new file mode 100644 index 0000000..079a9b4 Binary files /dev/null and b/res/166500/55df71faed43b37a8ac242120a72d.jpg differ diff --git a/res/166500/988d826212a6eed023ab99284971d.jpg b/res/166500/988d826212a6eed023ab99284971d.jpg new file mode 100644 index 0000000..14baf83 Binary files /dev/null and b/res/166500/988d826212a6eed023ab99284971d.jpg differ diff --git a/res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg b/res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg new file mode 100644 index 0000000..ff4158d Binary files /dev/null and b/res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg differ diff --git a/res/166500/e0255871e984f61ee8dc1800b9184.jpg b/res/166500/e0255871e984f61ee8dc1800b9184.jpg new file mode 100644 index 0000000..5955e04 Binary files /dev/null and b/res/166500/e0255871e984f61ee8dc1800b9184.jpg differ diff --git a/res/166500/tmp000.jpg b/res/166500/tmp000.jpg new file mode 100644 index 0000000..7c27679 Binary files /dev/null and b/res/166500/tmp000.jpg differ diff --git a/res/embeded b/res/embeded new file mode 100644 index 0000000..c4a89a5 --- /dev/null +++ b/res/embeded @@ -0,0 +1,34 @@ +this is to be embeded. +//0216 +vim of clang - https://github.com/JBakamovic/yavide +# Usage overview +Category | Shortcut | Description +--------------------------------- | --------------------------------- | --------------------------------- +**Project management** | | + | `n` | Create new project + | `i` | Import project with already existing code base + | `o` | Open project + | `c` | Close project + | `s` | Save project + | `d` | Delete project +**Buffer management** | | + | `` | Close current buffer + | `` | Save current buffer + | `` | Go to next buffer + | `` | Go to previous buffer + | `` | Scroll buffer by one line (down) + | `` | Scroll buffer by one line (up) +**Buffer modes** | | + | `` | Enter the `normal` mode + | `` | Enter the `insert` mode (append after cursor) + | `` | Enter the `insert` mode (insert before cursor) + | `` | Enter the `visual` mode (line mode) + | `` | Enter the `visual` mode (character mode) +**Buffer editing** | | + | `` | Select all + | `` | Cut + | `` | Copy + | `` | Paste + | `` | Undo + | `` | Redo + | `` | Delete the whole line diff --git a/test/test_jpeg.py b/test/test_jpeg.py index 9fe4f03..e21e94d 100644 --- a/test/test_jpeg.py +++ b/test/test_jpeg.py @@ -1,10 +1,10 @@ __author__ = 'chunk' import numpy as np -import mjpeg -from mjpeg import base +from .. import mjpeg +from ..mjpeg import base -from common import * +from ..common import * timer = Timer() @@ -20,6 +20,8 @@ sample = [[7, 12, 14, -12, 1, 0, -1, 0], sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, 5908L, 59816L, 56765L] +package_dir = os.path.dirname(os.path.abspath(__file__)) + def test_setblocks(): """ @@ -148,6 +150,13 @@ def test_iter(): print cnt +def test_jpeg(): + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/test3.jpg"), key=sample_key) + print ima.getQuality() + print ima.getCapacity() + sys.exit(0) + + if __name__ == '__main__': # timer.mark() # test_setblock() @@ -167,7 +176,7 @@ if __name__ == '__main__': # test_bitbyte() - ima = mjpeg.Jpeg("res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg", key=sample_key) + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg"), key=sample_key) print ima.getQuality() print ima.getCapacity() sys.exit(0) diff --git a/test/test_steg.py b/test/test_steg.py index 6942e3c..776c9c1 100644 --- a/test/test_steg.py +++ b/test/test_steg.py @@ -4,10 +4,11 @@ import numpy as np import pylab as P import pylab as plt -import mjpeg -from msteg.steganography import LSB, F3, F4, F5 -from common import * +from .. import mjpeg +from ..msteg.steganography import LSB, F3, F4, F5 +from ..common import * +package_dir = os.path.dirname(os.path.abspath(__file__)) timer = Timer() @@ -25,16 +26,24 @@ sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 565 txtsample = [116, 104, 105, 115, 32, 105, 115, 32, 116, 111, 32, 98, 101, 32, 101, 109, 98, 101, 100, 101, 100, 46, 10] + +def test_F3(): + f3test = F3.F3() + f3test.embed_raw_data(os.path.join(package_dir, "../res/test3.jpg"), os.path.join(package_dir, "../res/embeded"), + os.path.join(package_dir, "../res/steged.jpg")) + f3test.extract_raw_data(os.path.join(package_dir, "../res/steged.jpg"), + os.path.join(package_dir, "../res/extracted.jpg")) + + if __name__ == '__main__': - # f3test = F3.F3() - # f3test = F4.F4(sample_key) - f3test = F5.F5(sample_key, 1) - # f3test.embed_raw_data("res/test3.jpg", "res/embeded", "res/steged.jpg") - f3test.embed_raw_data("res/thulib2.jpg", "res/lena64gray.jpg", "res/steged.jpg") - - # f3test2 = F4.F4(sample_key) - f3test.extract_raw_data("res/steged.jpg", "res/extracted.jpg") - print f3test.get_key() + # # f3test = F4.F4(sample_key) + # f3test = F5.F5(sample_key, 1) + # # f3test.embed_raw_data("res/test3.jpg", "res/embeded", "res/steged.jpg") + # f3test.embed_raw_data("res/thulib2.jpg", "res/lena64gray.jpg", "res/steged.jpg") + # + # # f3test2 = F4.F4(sample_key) + # f3test.extract_raw_data("res/steged.jpg", "res/extracted.jpg") + # print f3test.get_key() # f5test = F5.F5(sample_key, 1) -- libgit2 0.21.2