1

I'm currently try to normalise depth image i receive from a depth camera with cv2.

I tried the following already: I used this line of code to normalise the images I receive between a value of 0 and 1 :

 cv2.normalize(depth_array, depth_array, 0, 1, cv2.NORM_MINMAX)

The problem I have with this sort of normalisation is that my depth images are not normalised between two set values but normalised between the maximum and minimum values of my depth_array which results in the closest objects being always black.

I want to change that it normalised between two set values, like [0 8] -> [0 1]. When googleing I have not found anything that does what I want to do. Is there a way to normalise an image between two set values?

beaker
  • 16,331
  • 3
  • 32
  • 49
Ronnee
  • 21
  • 1
  • I don't understand what you want. Is it that you want normalise values only in the range [0, 8], or is [0, 8] -> [0, 1] a reference point, so that 9 -> 1.125? – Reti43 Feb 15 '21 at 12:12
  • 1
    [Is this what you are after?](https://stackoverflow.com/a/39037135/3595907) – DrBwts Feb 15 '21 at 12:41
  • Does this answer your question? [Normalizing images in OpenCV](https://stackoverflow.com/questions/38025838/normalizing-images-in-opencv) (Found by @DrBwts) – beaker Feb 15 '21 at 17:32

1 Answers1

1

Reframes generally have this sort of structure:

# linear reframe [min1, max1] -> [min2, max2]
def reframe(value, min1, max1, min2, max2):
    value -= min1;
    value /= (max1 - min1);
    value *= (max2 - min2);
    value += min2;
    return value;

Using this we can see what we need to do to the whole image to get this to work. Assuming that we are going from [low, high] -> [0, 1] we can see that we just need to subtract "low" from the whole image and then divide it all by (high - low). This type of reframe will also extrapolate.

import cv2
import numpy as np

# load images
img = cv2.imread("one.png");

# convert type to float
img = img.astype(np.float32);

# reframe
low = 100;
high = 200;
img -= low;
img /= (high - low);
Ian Chu
  • 2,924
  • 9
  • 14