# How do i normalize an image better?

Hi,

Im using a python script to recieve images from a depth camera and when i started reading in the values of each pixel i had to normalize it to actually display it with imshow()

So i used this command to normalize my image:
cv2.normalize(depth_array, depth_array, 0, 1, cv2.NORM_MINMAX)

depth_array is a 2D numpy array that contains the values for each pixel.

After working some time with it I realised that the closest objects were always the darkest no matter how near they were and it realised that it takes all the read in values and normalises the between the min and max values that were read.

So i want that the images are normalised from the minimum distance of the depth camer to the maximum distance of it, so that 0.2 - 8 gets normalised between 0 and 1.

Is there a different way to normalize the image so that it works like i need to?

Im really sorry for the bad english, im no native speaker.

Thanks a lot in advance

Hi,
I think thatâ€™s cv.normalize can help you

``````m = np.array([1,2,3,4,5,6,7,8,9])
p = np.zeros(shape=m.shape)
p = cv.normalize(m,p,alpha=255,beta=-5,norm_type=cv.NORM_MINMAX)
print(p)
p = cv.normalize(m,p,alpha=255,beta=-5,norm_type=cv.NORM_MINMAX, dtype=cv.CV_8UC1)
print(p)
``````

results are
[[ -5]
[ 28]
[ 60]
[ 92]
[125]
[158]
[190]
[222]
[255]]

and

[[ 0]
[ 28]
[ 60]
[ 92]
[125]
[158]
[190]
[222]
[255]]

Thanks a lot and thank you for your help.

This is what ive been looking for.

Do you know a data type which is between 0 and 1?

There is no data type between 0 and 1 but you can use CV_32F or CV_64F for 32 bits or 64 bits floating value. You have to check that all values are in range 0 to 1