OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 06 Apr 2014 08:24:35 -0500Normalize hist with Norm_L1 doens't work ?http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/I am using the normalize function with this params:
normalize(hist, hist, 255, NORM_L1);
This should mean that the sum of every values inside the mat should equal to `= 255`
But later if i sum all values i get another value
sum(hist) != 255
To fix this error I need to call the normalize function like this:
normalize(hist, hist, 255, 0, NORM_L1);
Now I get:
sum(hist) == 255
Is this an intended behavior ?Sat, 05 Apr 2014 04:27:25 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/Answer by tuannhtn for <p>I am using the normalize function with this params:</p>
<pre><code>normalize(hist, hist, 255, NORM_L1);
</code></pre>
<p>This should mean that the sum of every values inside the mat should equal to <code>= 255</code> <br>
But later if i sum all values i get another value </p>
<pre><code>sum(hist) != 255
</code></pre>
<p>To fix this error I need to call the normalize function like this:</p>
<pre><code>normalize(hist, hist, 255, 0, NORM_L1);
</code></pre>
<p>Now I get:</p>
<pre><code>sum(hist) == 255
</code></pre>
<p>Is this an intended behavior ?</p>
http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?answer=31285#post-id-31285May be you misunderstand the normalize function (see more at [opencv's normalize](http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize)). In this case (normalize(hist, hist, 255, 0, NORM_L1);), the result is that hist will have max value as 255, min value as 0 and its norm (L1 type) is 255.Sat, 05 Apr 2014 05:09:03 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?answer=31285#post-id-31285Comment by tuannhtn for <p>May be you misunderstand the normalize function (see more at <a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize">opencv's normalize</a>). In this case (normalize(hist, hist, 255, 0, NORM_L1);), the result is that hist will have max value as 255, min value as 0 and its norm (L1 type) is 255.</p>
http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31317#post-id-31317Because it is a wrong call to normalize function, not the syntax but the semantic. When you call normalize(hist, hist, 255, NORM_L1);, indeed the norm type is NORM_L2 as default value of the normalize function, and the alpha is 255, beta is 2 (NORM_L1 is 2) (see normalize prototype at http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize for more details). So if you want to get sum(abs(hist))==255, you must invoke normalize function as normalize(hist, hist, 255, 0, NORM_L1);.Sun, 06 Apr 2014 08:24:35 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31317#post-id-31317Comment by yes123 for <p>May be you misunderstand the normalize function (see more at <a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize">opencv's normalize</a>). In this case (normalize(hist, hist, 255, 0, NORM_L1);), the result is that hist will have max value as 255, min value as 0 and its norm (L1 type) is 255.</p>
http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31310#post-id-31310Ok but with this: normalize(hist, hist, 255, NORM_L1); I **don't** get sum(abs(hist))==255Sun, 06 Apr 2014 05:50:03 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31310#post-id-31310Comment by yes123 for <p>May be you misunderstand the normalize function (see more at <a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize">opencv's normalize</a>). In this case (normalize(hist, hist, 255, 0, NORM_L1);), the result is that hist will have max value as 255, min value as 0 and its norm (L1 type) is 255.</p>
http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31286#post-id-31286You are wrong. When NORM_L1 only the norm-1 is = 255, not the max value of the hist = 255Sat, 05 Apr 2014 05:30:29 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31286#post-id-31286Comment by tuannhtn for <p>May be you misunderstand the normalize function (see more at <a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?#normalize">opencv's normalize</a>). In this case (normalize(hist, hist, 255, 0, NORM_L1);), the result is that hist will have max value as 255, min value as 0 and its norm (L1 type) is 255.</p>
http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31287#post-id-31287Yes, the max and min values are wrong, but the norm is correct, so you will have sum(abs(hist))==255. That means your result is the intended value.Sat, 05 Apr 2014 06:06:08 -0500http://answers.opencv.org/question/31283/normalize-hist-with-norm_l1-doenst-work/?comment=31287#post-id-31287