Commit 80d90408 authored by Theo's avatar Theo
Browse files

Clean output

parent 4bb889da
......@@ -380,7 +380,22 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "923592dda7b24510bbea3060d7c8253d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(FloatProgress(value=0.0, description='Intra-only', max=250274.0, style=ProgressStyle(descriptio…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"### Intras ###\n",
"#sampler_intras = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = \"Intra-only\")\n",
......
%% Cell type:code id: tags:
``` python
#Import depencies
from NS.sampling import BIL as Sampler
import os
import rawpy
import matplotlib.pyplot as plt
import numpy as np
import skimage
from scipy.fftpack import dct, idct
```
%% Cell type:markdown id: tags:
# Embedding
This notebook is a toy example which perform a cover source switching from ISO100 to ISO200 using the rights *(a, b)* for the database. The sampling can be done using different methods : MVG, Cholesky and Rejection-Sampling.
%% Cell type:code id: tags:
``` python
cwd = os.getcwd()
cover_path = cwd+'/ISO100/EYED5607.DNG'
cover_name = os.path.basename(cover_path)
```
%% Cell type:markdown id: tags:
## 1 Sampling of undecimated DCT coefficients:
Available sampling strategies :
* Using MVG/Cholesky over 4 lattices
* Using MVG/Cholesky to preserve intra correlations only
* Using MVG/Cholesky to sample under independance hypothesis of DCT coefficients
%% Cell type:markdown id: tags:
### 1.1.a Using MVG/Cholesky over 4 lattices
The two lines were used to obtain the result of the **Table I** and row **'J-Cov-NS'**.
| PE (%)/<br>JPEG QF | J-Cov-NS |
| :--- | :----: |
| 100 | 42.9 |
| 95 | 41.2 |
| 85 | 41.2 |
| 75 | 41.6 |
%% Cell type:code id: tags:
``` python
#sampler = Sampler.MVG(cover_path = cover_path, seed = 1234) #MVG
#sampler = Sampler.Cholesky(cover_path = cover_path, seed = 1234) #Cholesky
```
%% Cell type:markdown id: tags:
### 1.1.b Using MVG/Cholesky to preserve intra correlations only
To obtain the result of the **Table I** and row **'Intra-block correlations only'**.
| PE (%)/<br>JPEG QF |Intra-block<br>correlations only |
| :--- | :----: |
| 100 | 0.0 |
| 95 | 0.2 |
| 85 | 15.8 |
| 75 | 25.2 |
%% Cell type:code id: tags:
``` python
#sampler = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = "Intra-only") #MVG
#sampler = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "Intra-only") #Cholesky
```
%% Cell type:markdown id: tags:
### 1.1.c Using MVG/Cholesky to sample under independance hypothesis of DCT coefficients
Used to confirm the results obtained by Tomáš Denemark, Patrick Bas, and Jessica Fridrich in the paper called *'Natural Steganography in JPEG Compressed Images'* published in *'Electronic Imaging 2018'* and shown in the article at **Table I** and row **'Independent embedding'**.
| PE (%)/<br>JPEG QF |Independent<br>embedding |
| :--- | :----: |
| 100 | 0.0 |
| 95 | 0.5 |
| 85 | 10.8 |
| 75 | 27.0 |
%% Cell type:code id: tags:
``` python
#sampler = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = "Independant") #MVG
sampler = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "Independant") #Cholesky
```
%%%% Output: stream
/home/ttaburet/NS/module/tifs-ns/NS/tools/__init__.py:66: UserWarning: /home/ttaburet/NS/module/tifs-ns/temp_1.dng.tiff is a low contrast image
skimage.io.imsave(os.getcwd()+'/temp_'+_name+'.tiff', _RGB)
%% Cell type:markdown id: tags:
### 1.2 Quantization and full-frame cover's splitting
This code generate a quantized full-frame version of the undecimated DCT version of the stego and split into *512x512* quantized arrays.
%% Cell type:code id: tags:
``` python
stego, crops = sampler.computeStego().getStego(Qf = 100, crop_size = (512, 512))
```
%% Cell type:markdown id: tags:
## 2 Sampling of quantized DCT coefficients:
%% Cell type:markdown id: tags:
### 2.a Pseudo-embedding
Available sampling strategies :
* Pseudo-embedding
Details at section **II.C.1** and **Figure 1**, and performance of this embedding shown in the article at **Table I** and row **'Pseudo embedding'**.
| PE (%)/<br>JPEG QF |Pseudo<br>embedding |
| :--- | :----: |
| 100 | 40.2 |
| 95 | 40.9 |
| 85 | 41.9 |
| 75 | 41.3 |
%% Cell type:code id: tags:
``` python
#Pseudo-embedding
sampler = Sampler.Sampler(cover_path = cover_path, seed = 1234, strategy = "Pseudo") #Pseudo-embedding
#sampler = Sampler.Sampler(cover_path = cover_path, seed = 1234, strategy = "Pseudo-spatial") #Pseudo-embedding spatial
#FULL-SIZE
stego = sampler.computeStego().getStego()
```
%% Cell type:markdown id: tags:
### 2.b Rejection sampling
Available sampling strategies :
* Using rejection sampling over 4 lattices
* Using rejection sampling to preserve intra correlations only
* Using rejection sampling to sample under independance hypothesis of DCT coefficients
%% Cell type:code id: tags:
``` python
#RJ over 4-Lattices
#sampler = Sampler.RJ(cover = raw_cover, Qf = 100, K = 1, seed = 1234) #RJ - 4 lattices
```
%% Cell type:code id: tags:
``` python
#RJ : intra-only
#sampler = Sampler.RJ(cover = raw_cover, Qf = 100, K = 1, seed = 1234, strategy = "Intra-only") #RJ - intra
```
%% Cell type:code id: tags:
``` python
#RJ : independant
#sampler = Sampler.RJ(cover = raw_cover, Qf = 100, K = 1, seed = 1234, strategy = "Independant") #RJ - independant
```
%% Cell type:markdown id: tags:
## 3 Quantize and crop:
%% Cell type:code id: tags:
``` python
stego, crops = sampler.computeStego().getStego(crop_size = (512, 512))
```
%% Cell type:code id: tags:
``` python
#FULL-SIZE
stego = sampler.computeStego().getStego()
```
%% Cell type:markdown id: tags:
## 4 Simplified pipelines:
### Pseudo-spatial
Generation of a 16 bits stego image from the simple addition of Gaussian noise to perform cover source switching.
$\mathbf{X}_{ISO_{2}}^{Spatial}=\mathrm{Dev}^{Spatial}(\mathbf{X}_{ISO_{1}}^{RAW}+\mathcal{N}\left(ISO_{1}\longrightarrow ISO_{2}\right))$
%% Cell type:code id: tags:
``` python
#Pseudo-embedding in spatial domain
sampler = Sampler.Sampler(cover_path = cover_path, seed = 1234, strategy = "Pseudo-spatial")
stego_unquantized, crops = sampler.computeStego().getStego(crop_size = (512, 512))
```
%% Cell type:markdown id: tags:
### Pseudo-JPEG
Generation of a 8 bits JPEG stego image from the simple addition of Gaussian noise to perform cover source switching.
$\mathbf{X}_{ISO_{2}}^{JPEG}=\mathrm{Dev}^{JPEG}(\mathbf{X}_{ISO_{1}}^{RAW}+\mathcal{N}\left(ISO_{1}\longrightarrow ISO_{2}\right))$
%% Cell type:code id: tags:
``` python
sampler = Sampler.Sampler(cover_path = cover_path, seed = 1234, strategy = "Pseudo")
stego_unquantized, stego_quantized, crops = sampler.computeStego().getStego(Qf=100, crop_size = (512, 512))
```
%% Cell type:markdown id: tags:
### Sampling under independance hypothesis of DCT coefficients
Used to confirm the results obtained by Tomáš Denemark, Patrick Bas, and Jessica Fridrich in the paper called *'Natural Steganography in JPEG Compressed Images'* published in *'Electronic Imaging 2018'* and shown in the article at **Table I** and row **'Independent embedding'**.
| PE (%)/<br>JPEG QF |Independent<br>embedding |
| :--- | :----: |
| 100 | 0.0 |
| 95 | 0.5 |
| 85 | 10.8 |
| 75 | 27.0 |
Generation of a 8 bits JPEG stego image by adding a noise whose variances are estimated without taking into account neighbouring modes from inter and intra blocks correlations.
$\mathbf{X}_{ISO_{2}}^{JPEG}=\mathrm{Dev}^{DCT\rightarrow JPEG}\left(\mathrm{Dev}^{RAW\rightarrow DCT}\left(\mathbf{X}_{ISO_{1}}^{RAW}\right)+\mathcal{N}_{indepedant}^{DCT}\left(ISO_{1}\longrightarrow ISO_{2}\right)\right)$
%% Cell type:code id: tags:
``` python
### Independant ###
#sampler_independant = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = "Independant")
sampler_independant = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "Independant")
#sampler_independant = Sampler.RJ(cover_path = cover_path, seed = 1234, strategy = "Independant")
stego_unquantized, stego_quantized, crops = sampler_independant.computeStego().getStego(Qf=100, crop_size = (512, 512))
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
### Sampling to preserve intra correlations only
To obtain the result of the **Table I** and row **'Intra-block correlations only'**.
| PE (%)/<br>JPEG QF |Intra-block<br>correlations only |
| :--- | :----: |
| 100 | 0.0 |
| 95 | 0.2 |
| 85 | 15.8 |
| 75 | 25.2 |
Generation of a 8 bits JPEG stego image by adding a noise whose variances are estimated by taking into account neighbouring only the correlations within the modes that belong to the same block.
$\mathbf{X}_{ISO_{2}}^{JPEG}=\mathrm{Dev}^{DCT\rightarrow JPEG}\left(\mathrm{Dev}^{RAW\rightarrow DCT}\left(\mathbf{X}_{ISO_{1}}^{RAW}\right)+\mathcal{N}_{intra}^{DCT}\left(ISO_{1}\longrightarrow ISO_{2}\right)\right)$
%% Cell type:code id: tags:
``` python
### Intras ###
#sampler_intras = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = "Intra-only")
sampler_intras = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "Intra-only")
#sampler_intras = Sampler.RJ(cover_path = cover_path, seed = 1234, strategy = "Intra-only")
#Crops
stego_unquantized, stego_quantized, crops = sampler_intras.computeStego().getStego(Qf=100, crop_size = (512, 512))
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
### Sampling Using MVG/Cholesky over 4 lattices
The two lines were used to obtain the result of the **Table I** and row **'J-Cov-NS'**.
| PE (%)/<br>JPEG QF | J-Cov-NS |
| :--- | :----: |
| 100 | 42.9 |
| 95 | 41.2 |
| 85 | 41.2 |
| 75 | 41.6 |
$\mathbf{X}_{ISO_{2}}^{JPEG}=\mathrm{Dev}^{DCT\rightarrow JPEG}\left(\mathrm{Dev}^{RAW\rightarrow DCT}\left(\mathbf{X}_{ISO_{1}}^{RAW}\right)+\mathcal{N}_{intra+inter}^{DCT}\left(ISO_{1}\longrightarrow ISO_{2}\right)\right)$
%% Cell type:code id: tags:
``` python
### Intras ###
#sampler_4_lattices = Sampler.MVG(cover_path = cover_path, seed = 1234, strategy = "4-Lattices")
sampler_4_lattices = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "4-Lattices")
#sampler_4_lattices = Sampler.RJ(cover_path = cover_path, seed = 1234, strategy = "4-Lattices")
#Crops
stego_unquantized, stego_quantized, crops = sampler_4_lattices.computeStego().getStego(Qf=100, crop_size = (512, 512))
```
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: error
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-6-245badbc0969> in <module>
5
6 #Crops
----> 7 stego_unquantized, stego_quantized, crops = sampler_4_lattices.computeStego().getStego(Qf=100, crop_size = (512, 512))
~/NS/module/tifs-ns/NS/sampling/BIL/__init__.py in computeStego(self)
48 def computeStego(self):
49 if(self.strategy == "4-Lattices"):
---> 50 self.Embedding_4_lattices()
51 elif(self.strategy == "Intra-only"):
52 self.Embedding_intra_only()
~/NS/module/tifs-ns/NS/sampling/BIL/__init__.py in Embedding_4_lattices(self)
107 cov_L2[64:,64:] = cov_L4[5*64:,5*64:]
108
--> 109 dct_stego[i*16+16:i*16+24 , j*16+16:j*16+24 ] = self.process(cov_L2+self.eps*np.eye(5*64), obs, pos = {'i_left' : i*16+16, 'i_right' : i*16+24, 'j_left' : j*16+16, 'j_right' : j*16+24 })
110 pbar2.update(1)
111
~/NS/module/tifs-ns/NS/sampling/BIL/__init__.py in process(self, cov, obs, pos)
356 cov_22 = cov[64:,64:]
357
--> 358 reg_mat = np.dot(cov_12, np.linalg.pinv(cov_22))
359 cov_schur = cov_11 - np.dot(reg_mat, cov_21)#+ self.eps*np.eye(64)
360
<__array_function__ internals> in pinv(*args, **kwargs)
~/anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in pinv(a, rcond, hermitian)
1959 return wrap(res)
1960 a = a.conjugate()
-> 1961 u, s, vt = svd(a, full_matrices=False, hermitian=hermitian)
1962
1963 # discard small singular values
<__array_function__ internals> in svd(*args, **kwargs)
~/anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in svd(a, full_matrices, compute_uv, hermitian)
1624
1625 signature = 'D->DdD' if isComplexType(t) else 'd->ddd'
-> 1626 u, s, vh = gufunc(a, signature=signature, extobj=extobj)
1627 u = u.astype(result_t, copy=False)
1628 s = s.astype(_realType(result_t), copy=False)
KeyboardInterrupt:
%% Cell type:code id: tags:
``` python
```
......
......@@ -213,7 +213,7 @@ class Sampler():
M_1 = Covariance.getPhotositesToDctMatrix(1, 'Y')
# Lattices loaders
pbar1 = tqdm(total=((h//8-2))*((w//8-2)), desc = "Intra-only")
pbar1 = tqdm(total=(h//8-2)*(w//8-2), desc = "Intra-only")
#Lattice 1
for i, j in itertools.product(range(h//8-2), range(w//8-2)):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment