-
灰度图像的非线性变换 图像灰度非线性变换 DB = DA * DA / 255
-
python 代码
def test7():
# 图像灰度转换
img = cv2.imread(r"C:\images\lena.jpg")
grayimage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 获取图像高度和宽度
height = grayimage.shape[0]
width = grayimage.shape[1]
# 创建一幅图像
result = np.zeros((height, width), np.uint8)
#应该是平方,所以相当于让白色的更加白 黑色的更加黑
# 图像灰度非线性变换 DB = DA * DA / 255
for i in range(height):
for j in range(width):
gray = int(grayimage[i, j]) * int(grayimage[i, j]) / 255
result[i, j] = np.uint8(gray)
# 显示图像
cv2.imshow("Gray Image", grayimage)
cv2.imshow("Result", result)
# 等待显示
cv2.waitKey(0)
cv2.destroyAllWindows()