Commit fad8d727ae9e3a6f9c7bc90becac64435998d2e4
1 parent
5a7c47ec
Exists in
master
so you want to set...?
Showing
3 changed files
with
42 additions
and
28 deletions
Show diff stats
jpegObj/__init__.py
@@ -53,7 +53,7 @@ class Jpeg(Jsteg): | @@ -53,7 +53,7 @@ class Jpeg(Jsteg): | ||
53 | Jsteg.__init__(self, file, **kw) | 53 | Jsteg.__init__(self, file, **kw) |
54 | self.verbosity = verbosity | 54 | self.verbosity = verbosity |
55 | if verbosity > 0: | 55 | if verbosity > 0: |
56 | - print "[jpeg.__init__] Image size %ix%i" % (self.coef_arrays[0].shape) | 56 | + print "[Jpeg.__init__] Image size %ix%i" % (self.coef_arrays[0].shape) |
57 | if key != None: | 57 | if key != None: |
58 | self.key = key | 58 | self.key = key |
59 | elif rndkey: | 59 | elif rndkey: |
@@ -187,13 +187,40 @@ class Jpeg(Jsteg): | @@ -187,13 +187,40 @@ class Jpeg(Jsteg): | ||
187 | cID = self.getCompID(channel) | 187 | cID = self.getCompID(channel) |
188 | return self.coef_arrays[cID] | 188 | return self.coef_arrays[cID] |
189 | 189 | ||
190 | + def setCoefMatrix(self, matrix, channel="Y"): | ||
191 | + v, h = self.getCoefMatrix(channel).shape | ||
192 | + assert matrix.shape == (v, h), "matrix is expected of size (%d,%d)" % (v, h) | ||
193 | + | ||
194 | + cID = self.getCompID(channel) | ||
195 | + self.coef_arrays[cID] = matrix | ||
196 | + | ||
197 | + | ||
190 | def getCoefBlocks(self, channel="Y"): | 198 | def getCoefBlocks(self, channel="Y"): |
191 | """ | 199 | """ |
192 | This method returns the coefficient matrix for the given | 200 | This method returns the coefficient matrix for the given |
193 | colour channel (as a 4-D tensor: (v,h,row,col)). | 201 | colour channel (as a 4-D tensor: (v,h,row,col)). |
194 | """ | 202 | """ |
203 | + if channel == "All": | ||
204 | + return [ | ||
205 | + np.array([np.split(arr, arr.shape[1] / 8, axis=1) for arr in np.split(compMat, compMat.shape[0] / 8)]) | ||
206 | + for compMat in self.coef_arrays] | ||
207 | + | ||
195 | compMat = self.getCoefMatrix(channel="Y") | 208 | compMat = self.getCoefMatrix(channel="Y") |
196 | - return np.array([np.split(arr,arr.shape[1]/8, axis=1) for arr in np.split(compMat,compMat.shape[0]/8)]) | 209 | + return np.array([np.split(arr, arr.shape[1] / 8, axis=1) for arr in np.split(compMat, compMat.shape[0] / 8)]) |
210 | + | ||
211 | + def getCoefBlock(self, channel="Y", loc=(0, 0)): | ||
212 | + """ | ||
213 | + This method returns the coefficient matrix for the given | ||
214 | + colour channel (as a 4-D tensor: (v,h,row,col)). | ||
215 | + """ | ||
216 | + return self.getCoefBlocks(channel)[loc] | ||
217 | + | ||
218 | + | ||
219 | + def setCoefBlock(self, block, channel="Y", loc=(0, 0)): | ||
220 | + assert block.shape == (8, 8), "block is expected of size (8,8)" | ||
221 | + cID = self.getCompID(channel) | ||
222 | + v, h = loc[0] * 8, loc[1] * 8 | ||
223 | + self.coef_arrays[cID][v:v + 8, h:h + 8] = block | ||
197 | 224 | ||
198 | # Decompression | 225 | # Decompression |
199 | # ------------- | 226 | # ------------- |
jpegObj/__init__.pyc
No preview for this file type
yaj.py
1 | __author__ = 'chunk' | 1 | __author__ = 'chunk' |
2 | 2 | ||
3 | -# import mjsteg | ||
4 | import numpy as np | 3 | import numpy as np |
5 | - | ||
6 | -# a = mjsteg.Jsteg("res/test2.jpg") | ||
7 | -# compY,compCr,compCb = a.coef_arrays | ||
8 | -# | ||
9 | -# res = np.array([np.split(arr,arr.shape[1]/8, axis=1) for arr in np.split(compY,compY.shape[0]/8)]) | ||
10 | -# | ||
11 | -# print res.shape | ||
12 | -# | ||
13 | -# print res[0,0:20] | ||
14 | - | ||
15 | import jpegObj | 4 | import jpegObj |
16 | 5 | ||
17 | b = jpegObj.Jpeg("res/test2.jpg") | 6 | b = jpegObj.Jpeg("res/test2.jpg") |
18 | -c = b.getCoefBlocks(channel='Y') | ||
19 | - | ||
20 | -print c | ||
21 | -print c.shape | ||
22 | - | ||
23 | - | ||
24 | - | ||
25 | - | ||
26 | - | ||
27 | - | ||
28 | - | ||
29 | - | ||
30 | - | ||
31 | - | ||
32 | - | 7 | +# c = b.getCoefBlocks(channel='Y') |
8 | +# c1,c2,c3 = b.getCoefBlocks(channel='All') | ||
9 | +# print c2 | ||
33 | 10 | ||
34 | 11 | ||
12 | +print b.setCoefBlock(np.array([[0] * 8 for i in range(8)])) | ||
35 | 13 | ||
14 | +c = b.getCoefBlock(channel='Y', loc=(0, 0)) | ||
15 | +print c | ||
36 | 16 | ||
17 | +c = b.getCoefBlock(channel='Y', loc=(-1, 1)) | ||
18 | +print c | ||
37 | 19 | ||
20 | +b.setCoefMatrix(np.array([[0] * 800 for i in range(600)]),channel='Y') | ||
38 | 21 | ||
22 | +c = b.getCoefBlock(channel='Y', loc=(-1, 1)) | ||
23 | +print c | ||
39 | 24 | ||
25 | +c = b.getCoefBlock(channel='Y', loc=(0, 0)) | ||
26 | +print c | ||
40 | 27 | ||
41 | 28 |