# Normalize hist with Norm_L1 doens't 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 ?

edit retag close merge delete

Sort by » oldest newest most voted

May be you misunderstand the normalize function (see more at opencv's 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.

more

You are wrong. When NORM_L1 only the norm-1 is = 255, not the max value of the hist = 255

( 2014-04-05 05:30:29 -0500 )edit

Yes, 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.

( 2014-04-05 06:06:08 -0500 )edit

Ok but with this: normalize(hist, hist, 255, NORM_L1); I don't get sum(abs(hist))==255

( 2014-04-06 05:50:03 -0500 )edit

Because 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);.

( 2014-04-06 08:24:35 -0500 )edit

Official site

GitHub

Wiki

Documentation