我有很多灰度图像,我想用均值和标准差来规范化。我使用以下过程:
计算图像的均值和标准deviation.
然而,我得到了一个黑色的形象作为结果。我的代码有什么问题?
import cv2
img = cv2.imread('E.png') # read an image
gray_image = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY) # converting the image to grayscale image
img = cv2.resize(gray_image, (60, 60)) # Resize the image to the size 60x60 pixels
cv2.imwrite("Grayscale Image.png",img) #To write the result
mean, stdDev = cv2.meanStdDev(img) #Get Mean and Standard-deviation
image = (img-mean)/stdDev #Normalization process
cv2.imwrite("Normalized Image.png",image) #To write the result 输入图像:

灰度输出:

标准化图像输出:

发布于 2019-11-05 14:39:02
保存图像时,需要考虑数据类型。要将规范化图像保存为png,需要将规范化值缩放到整数范围(例如0,255),或者使用支持浮点格式的图像格式。
当使用z得分规范化时(如代码中所示),可以将其保存为png
image -= image.min()
image /= image.max()
image *= 255 # [0, 255] range
cv2.imwrite("Normalized Image.png", image)https://stackoverflow.com/questions/58713193
复制相似问题