## Copyright (C) 2012 Telematic and Telecommunication Laboratory (LTT),       
# Dipartimento di Ingegneria dell'Informazione- Università di Siena
# via Roma 56 53100 - Siena, Italy                   
# 
# Code authors: M. Barni, M. Fontani, B. Tondi
#----------------------------------------------------------------------
#Permission to use, copy, or modify this software and its documentation
#for educational and research purposes only and without fee is hereby
#granted, provided that this copyright notice and the original authors'
#names appear on all copies and supporting documentation. This program
#shall not be used, rewritten, or adapted as the basis of a commercial
#software or hardware product without first obtaining permission of the
#authors. The authors make no representations about the suitability of
#this software for any purpose. It is provided "as is" without express
#or implied warranty.
#----------------------------------------------------------------------
#
#This is an implementation of the algorithm for removing statistical
#traces left into the histogram of an image by any processing operator. 
#Please refer to the following paper:
#
#M. Barni, M. Fontani, B. Tondi, "A Universal Technique to Hide Traces of 
#Histogram-Based Image Manipulations", ACM Int. Workshop on Multimedia and 
#Security (MMSEC) 2012, Coventry, UK, 2012.
#
#Kindly report any suggestions or corrections to marco.fontani@unisi.it
#
#----------------------------------------------------------------------

param DiscMax >= 0 integer;
param X >= 3 integer;
param N1 >= 100 integer;
param N2 >= 100 integer;
param D >= 0 integer;

param e = 0.0001;

set I ; 
# set C within I cross I;

param ny{I} >= 0, <= N1;
param nt{I} >= 0, <= N2;


#check : sum{i in I} ny[i] = N1;
#check : sum{i in I} Pz[i] = 1.0;  # check banale ma non funzionano

var n{i in I, j in I};

minimize divergence: sum{i in I} ((ny[i] + sum{k in I : k != i}n[k,i] - sum{k in I: k!= i} n[i,k])/ N1) * log(((ny[i] + sum{k in I : k != i}n[k,i] - sum{k in I: k!= i} n[i,k] + e)/N1)/((nt[i]+ e)/N2));

# minimize divergence: sum{i in I} ((sum{k in I}n[k,i])/ N1) * log(((sum{k in I}n[k,i] + e)/N1)/((nt[i]+ e)/N2));


subject to vincoloPositivit�1{i in I}:
ny[i] + sum{k in I: k != i} n[k,i] - sum{k in I: k != i } n[i,k] >= 0;

subject to vincoloPositivit�2{i in I, j in I}:
n[i,j] >= 0;

subject to vincoloPositivit�3{i in I}:
ny[i] - sum{k in I: k != i } n[i,k] >= 0;

#elimino ora i salti > 10.....

subject to vincoloSalti{i in I,  j in I: abs(i - j) > DiscMax}: # non perdo soluzioni imponendo questo vincolo
n[i,j] = 0;

#subject to vincoloConservazioneElementi:
#sum{i in I, j in I} n[i,j] = N1;

#subject to vincoloMaxDistorsione:
#sum{i in I, j in I : i!= j} n[i,j]* abs(i - j) <= D;

subject to vincoloConservazioneNy{i in I}:
sum{k in I} n[i,k] = ny[i];




 



