diff --git a/readme.md b/readme.md index f12a2175b8bd446380634a96d86831a6424c4da0..bd38f4d4dbeaf21212397baf1b264da2d438ca1f 100644 --- a/readme.md +++ b/readme.md @@ -77,8 +77,11 @@ To do the Gradient Descent, one needs to compute Finally that we discussed about all the steps of the protocol, here the explanation of which parameters to pass in the CLI with main.py: * begin_step: first iteration of the protocol. Should be equals to 0 if you never launched it. +* server: 'yes' or 'no'. If you use a server and can launch command via slurm files, you can use 'yes' and probably you need to custom function 'run_job' in write_jobs.py to adapt it to you server. If it is not available, use 'no'. +* name_account: If run on a server, name of the account from which launch the computations. * number_step: for how many further iteration to lauchn the protocol * folder_model: absolute path leading to the folder './models/' stored in this folder. It contains the model and the architectures of the steganalysts networks. +* permutation_files: path to the numpy array, containing a permutation of range(1,n), where n is the total number of samples. The $train_size first indices are for the train set, the following $valid_size are for the validation set and the last $test_size are the the test set. * data_dir_prot: folder where all the stegos and classifiers produced during the algorithm are saved. * data_dir_cover: folder containing all cover images in the .npy format. One file for each image is required. * data_dir_stego_0: folder containing stegos at iteration 0, in the same format as cover images. @@ -108,7 +111,6 @@ Finally that we discussed about all the steps of the protocol, here the explanat - # Files and folders in the root ##### Folders diff --git a/tools_jpeg.py b/tools_jpeg.py new file mode 100644 index 0000000000000000000000000000000000000000..f0ec045e1fccb432a78f17c610e6132bd79d47b2 --- /dev/null +++ b/tools_jpeg.py @@ -0,0 +1,35 @@ +import numpy as np +import os +from scipy import fftpack +from numpy.lib.stride_tricks import as_strided + + +def block_view(A, block= (8,8)): + """Provide a 2D block view to 2D array. No error checking made. + Therefore meaningful (as implemented) only for blocks strictly + compatible with the shape of A.""" + # simple shape and strides computations may seem at first strange + # unless one is able to recognize the 'tuple additions' involved ;-) + shape= (A.shape[0]// block[0], A.shape[1]// block[1])+ block + strides= (block[0]* A.strides[0], block[1]* A.strides[1])+ A.strides + return as_strided(A, shape= shape, strides= strides) + +def segmented_stride(M, fun, blk_size=(8,8), overlap=(0,0)): + # This is some complex function of blk_size and M.shape + B = block_view(M, block=blk_size) + B[:,:,:,:] = fun(B) + return M + +def decompress(c_coeffs, c_quant): + # Decompress DCT coefficients C using quantization table Q + H = c_coeffs.shape[0] + W = c_coeffs.shape[1] + assert H % 8 == 0, 'Wrong image size' + assert W % 8 == 0, 'Wrong image size' + I = np.zeros((H,W),dtype=np.float64) # Returns Y, Cb and Cr + # this multiplication is done on integers + fun = lambda x : np.multiply(x,c_quant) + C = np.float64(segmented_stride(c_coeffs, fun)) + fun = lambda x: fftpack.idct(fftpack.idct(x, norm='ortho',axis=2), norm='ortho',axis=3) + 128 + I[:,:,i] = segmented_stride(C, fun) + return I