Skip to content
Snippets Groups Projects
Commit b4c9cae2 authored by Taburet Théo's avatar Taburet Théo
Browse files

Force crop sizes to be //8 without reminder.

parent 2a2fac35
No related branches found
No related tags found
No related merge requests found
%% 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
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-102230b98ca7> in <module>
1 #sampler = Sampler.MVG(cover = raw_cover, seed = 1234, strategy = "Independant") #MVG
----> 2 sampler = Sampler.Cholesky(cover_path = cover_path, seed = 1234, strategy = "Independant") #Cholesky
TypeError: __init__() got an unexpected keyword argument 'cover_path'
%% 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()
```
......
......@@ -259,6 +259,7 @@ class Sampler():
self.stego_quantized = compute_jpeg_from_dct(compute_dct_domain(self.stego), Q_Y)#[8:-16,16:-8]
if(crop_size != (0, 0) and len(list(crop_size)) == 2):
crop_size = crop_size[0]-crop_size[0]%8, crop_size[1]-crop_size[1]%8
s_i, s_j = self.stego.shape[0]//crop_size[0], self.stego.shape[1]//crop_size[1]
return self.stego_quantized, [ self.stego_quantized[crop_size[0]*i:crop_size[0]*(i+1), crop_size[1]*j:crop_size[1]*(j+1)] for i, j in itertools.product(range(s_i), range(s_j)) ]
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment