## 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) load('test.mat'); 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!

Dear Paolo,

I found the information posted in the Similarity threshold computation for Cox watermarking page very useful.

I’m actually going through the exercise of embedding a watermark by DCT.

I’m a beginner in MatLab and am not quite sure of my results.

I create a WM vector with “wVector = randn(n,1);”

and change the AC coefficients of the original matrix by doing:

for i= 2:n

dctPlusWM(I(i)) = ((B(i)*(1+0.1*wVector(i))));

end

([B,I] = sort(original DCT matrix, ‘descend’)

I’d apreciate if you could provide any feedback.

Regards,

Cleiton

Hi,

the idea behind your implementation is right, but you should sort the dct coefficients before the embedding. After the sorting embed the wm in the strongest coeffs skipping the first, so that you will not effect the AC component. After the embedding just reorder the dct coefficients and go back by using idct.

hope you found this helpful, otherwise just write me again!

Oh now i got your post on cox watermarking .. i think now my problem will get solved soon….but can you please help me how to sort the cofficients???

Would you like to upload complete code …. plz

Thanks in advance ….

you mean cox embedding?

Or upload the code for cox embedding

Thanks in advance

Read the code: Iused function sort. Remember to skip first coefficient.

Don’t want to be unpolite here, but should read and google before asking.

I am trying to implementing cox watermarking for audio.

I am new to Matlab, so facing trouble.

How you generate watermak?

I wrote as:

“N=1000;

Wm=randn(1,N);”

is it ok? or i have to do something additional?

thanx

hi,

you can do something like:

N=1000;

watermark=round(rand(1,N));

in this case i used the round() function so that the mark will be binary.

Anyhow this solution is not good, because in the recovery part you will need the same watermark for the similarity compution.

You have three solutions:

1) go further as above, then store the watermark on disk as a .mat file (see save function). In recovery part you can read the file

2) as above, but instead of saving the watermark, you can just hardcode it in recovery file

3) generate the watermark using (for example):

randn(‘state’,506);

w=randn(1,1000);

so that in the recovery function you will be able to generate exactly the same watermark

ps, try this and if you are still in trouble i can write a post on this topic

I wrote for similarity:

“function [Sim] = Similarity(Wmark, ExtractedWmark,N)

[r,c] = size(Wmark);

if (c ~= 1 && r ~= 1)

error(‘Wmark should be a vector.’)

end

[r,c] = size(ExtractedWmark);

if (c ~= 1 && r ~= 1)

error(‘ExtractedWmark should be a vector.’)

end

Sim=zeros(1,N);

for k=1:N

Sim(k) = Wmark(k) * ExtractedWmark(k) / sqrt(ExtractedWmark(k) * ExtractedWmark(k));

end”

why do you do this? i mean, if you have the original wm and the extracted wm you can just do:

SIM = w * w_ext’ / sqrt( w_ext * w_ext’ )

I used a cicle in my code only because i was looking for a threshold… plus are you sure that you can do the vectorial product? as you can see i used the apostrophe character to do that.

Don’t you it is strange that actually you are comparing the similarity of original embedded watermark with itself at index 1000?

no

Help me!

Programming in matlab

—————————————————————–

I’m making a Project on digital watermarking on digital images.

I have to implementate it by DCT domain, embed text watermark in image to protected copyright.

Would you please share with me.!!

Thank you everyone, thank you verymuch !!!!!!!

And now:

matlab code project: digital signature on RSA (or DSS, ..) //on digital image.

MD5 (or SHA,..) // on digital image

Please contact me : manhphuc.cnt48@gmail.com

supermario.lovely@yahoo.com

Thanks!

please post the code for Cox watermarking embedding and extracting

Dear Paolo,

I found the information posted in the LSB watermarking page very useful.

can you please help me with this question that how one should modify the algorithms sothat the watermark can survive attacks such as LSB truncation or scaling and rotation.

Any help would be much appriciated

Nora

Hello, LSB is just a study algorithm. You may want ti search on IEEE for other algorithms or design your own strategy based on tour needs