Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on an assignment where we have to use the NEC algorithm for inserting and extracting a watermark from an image file. Using the techniques described in this article. I am at the point where I want to apply the similarity function in Matlab:

$$\begin{align*} X &= (x_1,x_2,\dotsc,x_n)\quad\text{original watermark}\\ X^* &= (x^*_1,x^*_2,\dotsc,x^*_n)\quad\text{extracted watermark}\\\\ sim(X, X^*) &= \frac{X^* * X}{\sqrt{X^* * X^*}}\\ \end{align*}$$

After that, the purpose is to compare the result to a threshold value to take a decision.

EDIT Question: what is the best way to implement the sim() function? The values of the watermark vectors are doubles.

share|cite|improve this question
I don't see a question. – Qiaochu Yuan Feb 28 '13 at 4:39
up vote 1 down vote accepted

Well if you talking from an efficient/fastest/concise point of view, then MATLAB is vectorized. Let x1 be the vector of original watermark and let x2 be the vector of the extracted watermark then I would just do something like


or even

dot(x1,x2)/norm(x2,2). They are identical.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.