Commit 259ca19d020544331bf4097c9678a9721746d108
1 parent
d0be60e7
Exists in
develop
ohno! heterogeneity of components is a disaster.
Showing
11 changed files
with
91 additions
and
49 deletions
Show diff stats
mjpeg/__init__.py
... | ... | @@ -257,9 +257,12 @@ class Jpeg(Jsteg): |
257 | 257 | colour channel (as a 4-D tensor: (v,h,row,col)). |
258 | 258 | """ |
259 | 259 | if channel == "All": |
260 | - return np.array([ | |
261 | - [np.hsplit(arr, arr.shape[1] / 8) for arr in np.vsplit(compMat, compMat.shape[0] / 8)] for compMat in | |
262 | - self.coef_arrays]) | |
260 | + # return [ | |
261 | + # [np.hsplit(arr, arr.shape[1] / 8) for arr in np.vsplit(compMat, compMat.shape[0] / 8)] for compMat in | |
262 | + # self.coef_arrays] | |
263 | + return [ | |
264 | + np.array([np.hsplit(arr, arr.shape[1] / 8) for compMat in | |
265 | + self.coef_arrays for arr in np.vsplit(compMat, compMat.shape[0] / 8)])] | |
263 | 266 | |
264 | 267 | compMat = self.getCoefMatrix(channel) |
265 | 268 | 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): |
295 | 298 | return self.image_width, self.image_height |
296 | 299 | |
297 | 300 | def getCapacity(self, channel="All"): |
298 | - blocks = self.getCoefBlocks(channel) | |
299 | - print blocks.shape | |
300 | - return (np.sum(blocks[0] != 0) - np.size(blocks[0]) / 64) + (np.sum(blocks[1] != 0) - np.size( | |
301 | - blocks[1]) / 64) / 4 + (np.sum(blocks[2] != 0) - np.size(blocks[2]) / 64) / 4 | |
302 | - # return np.sum(np.array(self.coef_arrays)!=0) - np.size(self.coef_arrays) / 64 | |
301 | + # blocks = self.getCoefBlocks(channel) | |
302 | + # print blocks.shape | |
303 | + # return (np.sum(blocks[0] != 0) - np.size(blocks[0]) / 64) + (np.sum(blocks[1] != 0) - np.size( | |
304 | + # blocks[1]) / 64) / 4 + (np.sum(blocks[2] != 0) - np.size(blocks[2]) / 64) / 4 | |
305 | + capacity = 0 | |
306 | + if channel == 'All': | |
307 | + for blocks in self.getCoefBlocks(channel): | |
308 | + print blocks | |
309 | + capacity += (np.sum(np.array(blocks) != 0) - np.size(blocks) / 64) | |
310 | + else: | |
311 | + blocks = self.getCoefBlocks(channel) | |
312 | + capacity += (np.sum(np.array(blocks) != 0) - np.size(blocks) / 64) | |
313 | + return capacity | |
303 | 314 | |
304 | 315 | |
305 | 316 | def getQuality(self): |
... | ... | @@ -359,28 +370,6 @@ class Jpeg(Jsteg): |
359 | 370 | # assert max( abs(S).flatten() ) <=128, "Image colours out of range" |
360 | 371 | return (S + 128 ).astype(np.uint8) |
361 | 372 | |
362 | - # Complete, general decompression is not yet implemented:: | |
363 | - | |
364 | - def getimage(self): | |
365 | - """ | |
366 | - Decompress the image and a PIL Image object. | |
367 | - """ | |
368 | - | |
369 | - # Probably better to use a numpy image/array. | |
370 | - | |
371 | - raise NotImplementedError, "Decompression is not yet implemented" | |
372 | - | |
373 | - # We miss the routines for upsampling and adjusting the size | |
374 | - | |
375 | - L = len(self.coef_arrays) | |
376 | - im = [] | |
377 | - for i in range(L): | |
378 | - C = self.coef_arrays[i] | |
379 | - if C != None: | |
380 | - Q = self.quant_tables[self.comp_info[i]["quant_tbl_no"]] | |
381 | - im.append(ibdct(dequantise(C, Q))) | |
382 | - return Image.fromarray(im) | |
383 | - | |
384 | 373 | |
385 | 374 | # Calibration |
386 | 375 | # ----------- | ... | ... |
msteg/__init__.py
... | ... | @@ -2,8 +2,9 @@ __author__ = 'chunk' |
2 | 2 | |
3 | 3 | import numpy as np |
4 | 4 | |
5 | -from ..mjpeg import Jpeg | |
6 | 5 | from ..common import * |
6 | +from ..mjpeg import Jpeg | |
7 | + | |
7 | 8 | |
8 | 9 | __all__ = ['StegBase', 'sample_key'] |
9 | 10 | |
... | ... | @@ -33,7 +34,7 @@ class StegBase(object): |
33 | 34 | """ |
34 | 35 | self.cov_jpeg = Jpeg(img_path) |
35 | 36 | self.key = self.cov_jpeg.getkey() |
36 | - self.cov_data = self.cov_jpeg.getCoefBlocks() | |
37 | + self.cov_data = self.cov_jpeg.getCoefBlocks('All') | |
37 | 38 | return self.cov_data |
38 | 39 | |
39 | 40 | |
... | ... | @@ -49,7 +50,7 @@ class StegBase(object): |
49 | 50 | self.hid_data = np.array(raw, dtype=np.uint8) |
50 | 51 | |
51 | 52 | if np.size(self.hid_data) * 8 > np.size(self.cov_data): |
52 | - raise Exception("Cover image is too small to embed data.Cannot fit %d bits in %d DCT coefficients" % ( | |
53 | + print("[WARN] Cover image is too small to embed data.Cannot fit %d bits in %d DCT coefficients" % ( | |
53 | 54 | np.size(self.hid_data) * 8, np.size(self.cov_data))) |
54 | 55 | return self.hid_data |
55 | 56 | ... | ... |
130 KB
119 KB
89.9 KB
172 KB
111 KB
62.9 KB
... | ... | @@ -0,0 +1,34 @@ |
1 | +this is to be embeded. | |
2 | +//0216 | |
3 | +vim of clang - https://github.com/JBakamovic/yavide | |
4 | +# Usage overview | |
5 | +Category | Shortcut | Description | |
6 | +--------------------------------- | --------------------------------- | --------------------------------- | |
7 | +**Project management** | | | |
8 | + | `<Ctrl-s>n` | Create new project | |
9 | + | `<Ctrl-s>i` | Import project with already existing code base | |
10 | + | `<Ctrl-s>o` | Open project | |
11 | + | `<Ctrl-s>c` | Close project | |
12 | + | `<Ctrl-s>s` | Save project | |
13 | + | `<Ctrl-s>d` | Delete project | |
14 | +**Buffer management** | | | |
15 | + | `<Ctrl-c>` | Close current buffer | |
16 | + | `<Ctrl-s>` | Save current buffer | |
17 | + | `<Ctrl-Tab>` | Go to next buffer | |
18 | + | `<Ctrl-Shift-Tab>` | Go to previous buffer | |
19 | + | `<Ctrl-Down>` | Scroll buffer by one line (down) | |
20 | + | `<Ctrl-Up>` | Scroll buffer by one line (up) | |
21 | +**Buffer modes** | | | |
22 | + | `<ESC>` | Enter the `normal` mode | |
23 | + | `<a>` | Enter the `insert` mode (append after cursor) | |
24 | + | `<i>` | Enter the `insert` mode (insert before cursor) | |
25 | + | `<Shift-v>` | Enter the `visual` mode (line mode) | |
26 | + | `<v>` | Enter the `visual` mode (character mode) | |
27 | +**Buffer editing** | | | |
28 | + | `<Ctrl-a>` | Select all | |
29 | + | `<Ctrl-x>` | Cut | |
30 | + | `<Ctrl-c>` | Copy | |
31 | + | `<Ctrl-v>` | Paste | |
32 | + | `<Ctrl-z>` | Undo | |
33 | + | `<Ctrl-r>` | Redo | |
34 | + | `<Shift-s>` | Delete the whole line | ... | ... |
test/test_jpeg.py
1 | 1 | __author__ = 'chunk' |
2 | 2 | |
3 | 3 | import numpy as np |
4 | -import mjpeg | |
5 | -from mjpeg import base | |
4 | +from .. import mjpeg | |
5 | +from ..mjpeg import base | |
6 | 6 | |
7 | -from common import * | |
7 | +from ..common import * | |
8 | 8 | |
9 | 9 | timer = Timer() |
10 | 10 | |
... | ... | @@ -20,6 +20,8 @@ sample = [[7, 12, 14, -12, 1, 0, -1, 0], |
20 | 20 | sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 56572L, 36476L, 25695L, 61908L, 63014L, |
21 | 21 | 5908L, 59816L, 56765L] |
22 | 22 | |
23 | +package_dir = os.path.dirname(os.path.abspath(__file__)) | |
24 | + | |
23 | 25 | |
24 | 26 | def test_setblocks(): |
25 | 27 | """ |
... | ... | @@ -148,6 +150,13 @@ def test_iter(): |
148 | 150 | print cnt |
149 | 151 | |
150 | 152 | |
153 | +def test_jpeg(): | |
154 | + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/test3.jpg"), key=sample_key) | |
155 | + print ima.getQuality() | |
156 | + print ima.getCapacity() | |
157 | + sys.exit(0) | |
158 | + | |
159 | + | |
151 | 160 | if __name__ == '__main__': |
152 | 161 | # timer.mark() |
153 | 162 | # test_setblock() |
... | ... | @@ -167,7 +176,7 @@ if __name__ == '__main__': |
167 | 176 | |
168 | 177 | # test_bitbyte() |
169 | 178 | |
170 | - ima = mjpeg.Jpeg("res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg", key=sample_key) | |
179 | + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/166500/cecdb4b3fef5433faa3d24259e3e4.jpg"), key=sample_key) | |
171 | 180 | print ima.getQuality() |
172 | 181 | print ima.getCapacity() |
173 | 182 | sys.exit(0) | ... | ... |
test/test_steg.py
... | ... | @@ -4,10 +4,11 @@ import numpy as np |
4 | 4 | import pylab as P |
5 | 5 | import pylab as plt |
6 | 6 | |
7 | -import mjpeg | |
8 | -from msteg.steganography import LSB, F3, F4, F5 | |
9 | -from common import * | |
7 | +from .. import mjpeg | |
8 | +from ..msteg.steganography import LSB, F3, F4, F5 | |
9 | +from ..common import * | |
10 | 10 | |
11 | +package_dir = os.path.dirname(os.path.abspath(__file__)) | |
11 | 12 | |
12 | 13 | timer = Timer() |
13 | 14 | |
... | ... | @@ -25,16 +26,24 @@ sample_key = [46812L, 20559L, 31360L, 16681L, 27536L, 39553L, 5427L, 63029L, 565 |
25 | 26 | |
26 | 27 | txtsample = [116, 104, 105, 115, 32, 105, 115, 32, 116, 111, 32, 98, 101, 32, 101, 109, 98, 101, 100, 101, 100, 46, 10] |
27 | 28 | |
29 | + | |
30 | +def test_F3(): | |
31 | + f3test = F3.F3() | |
32 | + f3test.embed_raw_data(os.path.join(package_dir, "../res/test3.jpg"), os.path.join(package_dir, "../res/embeded"), | |
33 | + os.path.join(package_dir, "../res/steged.jpg")) | |
34 | + f3test.extract_raw_data(os.path.join(package_dir, "../res/steged.jpg"), | |
35 | + os.path.join(package_dir, "../res/extracted.jpg")) | |
36 | + | |
37 | + | |
28 | 38 | if __name__ == '__main__': |
29 | - # f3test = F3.F3() | |
30 | - # f3test = F4.F4(sample_key) | |
31 | - f3test = F5.F5(sample_key, 1) | |
32 | - # f3test.embed_raw_data("res/test3.jpg", "res/embeded", "res/steged.jpg") | |
33 | - f3test.embed_raw_data("res/thulib2.jpg", "res/lena64gray.jpg", "res/steged.jpg") | |
34 | - | |
35 | - # f3test2 = F4.F4(sample_key) | |
36 | - f3test.extract_raw_data("res/steged.jpg", "res/extracted.jpg") | |
37 | - print f3test.get_key() | |
39 | + # # f3test = F4.F4(sample_key) | |
40 | + # f3test = F5.F5(sample_key, 1) | |
41 | + # # f3test.embed_raw_data("res/test3.jpg", "res/embeded", "res/steged.jpg") | |
42 | + # f3test.embed_raw_data("res/thulib2.jpg", "res/lena64gray.jpg", "res/steged.jpg") | |
43 | + # | |
44 | + # # f3test2 = F4.F4(sample_key) | |
45 | + # f3test.extract_raw_data("res/steged.jpg", "res/extracted.jpg") | |
46 | + # print f3test.get_key() | |
38 | 47 | |
39 | 48 | # f5test = F5.F5(sample_key, 1) |
40 | 49 | ... | ... |