Home > Back-end >  Image fully black after normalizing to [0,1]
Image fully black after normalizing to [0,1]

Time:10-08

I'm trying to normalize an image to [0,1] like this:

img = cv2.imread('/home/images/'   name)
norm_image = cv2.normalize(img, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX)

And when I try to show it:

cv2.imshow('normalized', norm_image)
cv2.waitKey()

The image is fully black. How can I fix this?

CodePudding user response:

When you use cv2.imread to open an image, the default datatype is integer.

When you use cv2.normalize with no output datatype specified, the default is same type as the input, which is integer in this case.

It only makes sense to normalize an image between 0 - 1 using float values. Otherwise it's just 0 or 1.

Try adding the output datatype argument dtype=cv2.CV_32F

norm_image = cv2.normalize(img, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
  • Related