I wrote the following code to normalize an image using NORM_L1 in OpenCV. But the output image was just black. How to solve this?
JavaScript
x
21
21
1
import cv2
2
import numpy as np
3
import Image
4
5
img = cv2.imread('img7.jpg')
6
gray_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
7
a = np.asarray(gray_image)
8
9
10
dst = np.zeros(shape=(5,2))
11
12
b=cv2.normalize(a,dst,0,255,cv2.NORM_L1)
13
14
15
im = Image.fromarray(b)
16
17
im.save("img50.jpg")
18
19
cv2.waitKey(0)
20
cv2.destroyAllWindows()
21
Advertisement
Answer
If you want to change the range to [0, 1], make sure the output data type is float
.
JavaScript
1
3
1
image = cv2.imread("lenacolor512.tiff", cv2.IMREAD_COLOR) # uint8 image
2
norm_image = cv2.normalize(image, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
3