在 OpenCV 中标准化图像 [英] Normalizing images in OpenCV
本文介绍了在 OpenCV 中标准化图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了以下代码以在 OpenCV 中使用 NORM_L1 对图像进行标准化.但是输出图像是黑色的.如何解决这个问题?
I wrote the following code to work normalize an image using NORM_L1 in OpenCV. But the output image was just black.How to solve this ?
import cv2
import numpy as np
import Image
img = cv2.imread('img7.jpg')
gray_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
a = np.asarray(gray_image)
dst = np.zeros(shape=(5,2))
b=cv2.normalize(a,dst,0,255,cv2.NORM_L1)
im = Image.fromarray(b)
im.save("img50.jpg")
cv2.waitKey(0)
cv2.destroyAllWindows()
推荐答案
如果要将范围更改为 [0, 1],请确保输出数据类型为 float
.
If you want to change the range to [0, 1], make sure the output data type is float
.
image = cv2.imread("lenacolor512.tiff", cv2.IMREAD_COLOR) # uint8 image
norm_image = cv2.normalize(image, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
这篇关于在 OpenCV 中标准化图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文