I need to normalize an array that contains values between 0 to 1024 into an array that will contain values between 0-255. I am doing this in Java but I am wanting to understand what exactly does it mean to "normalize an array" rather than asking for exact code.
To normalize a vector in math means to divide each of its elements
to some value V so that the length/norm of the resulting vector is 1.
Turns out the needed V is equal to the length (norm) of the vector.
Say you have this array.
[-3, +4]
Its length (in Euclid metric) is: V = sqrt((-3)^2 + (+4)^2) = 5
So its corresponding normalized vector is:
[-3/5, +4/5]
Its length is now: sqrt ( (-3/5)^2 + (+4/5)^2 )
which is 1.
You can use another metric (e.g. I think Manhattan distance)
but the idea is the same. Divide each element of your array
by V
where V = || your_vector || = norm (your_vector)
.
So I think this is what is meant here.
See also:
http://www.fundza.com/vectors/normalize/
http://mathworld.wolfram.com/NormalizedVector.html
Normalize in this case essentially means to convert the value in your original scale to a value on a different scale. Something like this will do it:
x = origVal / 1024;
xNorm = 255 * x;
You will have to decide how you want to handle rounding.
So for example:
.5 = 512 / 1024;
127.5 = 255 * .5;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With