我有很多灰度图像要通过均值和标准差进行归一化,我遵循此过程:
1)计算图像的均值和标准差
2)从图像中减去平均值
3)然后将结果图像除以标准差
但是,我得到了黑色图像!
我的代码有什么问题?
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
归一化图像输出:https://ibb.co/7WxhwcJ
您的图像存储在uint8中,因为这是OpenCV的imread()
返回的格式。在这种情况下,OpenCV方法不会更改数据类型,因此当您尝试图像时,所有值都变为0。