### Archive

Posts Tagged ‘cox’

## Similarity threshold computation for Cox watermarking

If you dive into watermarking field, you will have to deal for sure with Cox embedding technique.

Cox’s embedding works in the transform domain (e.g. DCT or DWT) while LSB works in the spatial domain. The idea behind this technique is the following:

1) take an image and a watermark (let’s say the watermark is 512*512 binary)

2) compute the DCT (DWT) of the image, and compute all it’s coefficients

3) sort the coefficients preserving their position

4) we know that most of energy is (approximately) inside the first 1000 coefficients so we could easily embed the watermark inside the first 1024 coefficients by exploiting on each of these coefficients one of the following embedding:

• V'(i) = V'(i) * (1 + alpha*W(i))
• V'(i) = V(i)+ alpha*W(i)
• V'(i) = V(i) * e ^ (alpha*W(i))

where V(i) is the original value of the coefficient, V'(i) is the value of the coefficient after the embedding, W(i) is the watermark and alpha is a strength embedding factor.

5) Reorder the coefficients on the their original positions and perform an antitrasform

Since the code is pretty easy I will not post it here, but if you have troubles please just write me and I will make it available.

Ok, at this point we have a watermarked image…but what about the detection???

Well, you can’t recover the original watermark as you did for LSB watermarking, but you can assert whether your mark is inside the cover image or not. The procedure is the following:

1) take the watermarkded image

2) compute again the DCT (DWT) of the image, and compute all it’s coefficients

3) sort again the coefficients preserving their position

4) try to compute an approximate mark (Wap(i)) by inverting the formula you used in embedding

5) Check if the similarity between the original mark and Wap(i) is above a certain threshold, if so your watermark is present

To compute the threshold you have to run an experimental study; basically you must compute the similarity between many fake watermarks (e.g. 999) and the original watermark, than the similarity between your watermark and itself.

Similarity fuction is defined as: SIM(W,Wi) = (W * Wi) / sqrt(Wi * Wi)

When you have all the similarities, you may notice that you have many peaks you can see as noise, and a peak where you computed the similarity with itself. To set the threshold you just need to take the second peak and add it its 15%, so that you will rarely have false positive matching.

Here is the code to compute the similarity:

```function [threshold,sim_detection] = threshold_computation
watermarks=zeros(1000,1024);
%% generate 999 random fake (1,1024) watermarks
for i=1:999
watermarks(i,:)=round(rand(1,1024));
end
%% load from a mat file the original (512,512) watermark
%% (variable name is watermark as well)
wm=watermark;
%% reshape original watermark to (1,1024)
[r c]=size(wm);
w=reshape(wm,1,r*c);
w=round(rand(1,1024));
w=double(w);

%% add reshaped watermark as the 1000 element of watermarks set
watermarks(1000,:)=w;

%% for each watermark compute similarity detection and save result in a vector
sim_detection=zeros(1000);
for i=1:1000
sim_detection(i)=w*watermarks(i,:)'/sqrt(watermarks(i,:)*watermarks(i,:)');
end
%% sort values according to magnitude
[values,index]=sort(sim_detection,'descend');
threshold=values(1);
%% compute threshold
threshold=values(2)+((values(2)*10)/100);
end```

Let’s execute the code:

```>> [real_threshold,threshold_vec] = threshold_computation;
>> plot(threshold_vec,'DisplayName','threshold_vec','YDataSource','threshold_vec');```

Here is the result of the plot operation, in the abscissa we have the watermarks, while in the in ordinate we have the similarity computed for the given watermark (notice that in abscissa 1000 there is a peak of similarity due to the fact that for the computation we are using the real watermark). That’s all foks! Stay tuned!