python 用分组处理map() 将1维数组转换成2维RGB图像 实现RGB图像像素值整体操作 (如整体增强,整体转灰度值)代码实现
时间: 2024-06-05 10:06:00 浏览: 10
# 将1维数组转换成2维RGB图像
import numpy as np
# 假设原始图像大小为 100*100,通道数为 3
img = np.zeros((10000, 3), dtype=np.uint8) # 创建一个 10000*3 的 0 矩阵,作为示例
# 将 img 转换为 100*100*3 的 RGB 图像
img_reshape = img.reshape((100, 100, 3))
# 整体增强
img_enhanced = img_reshape * 1.2 # 将所有像素点的值乘以 1.2
# 整体转灰度值
img_gray = np.dot(img_reshape[..., :3], [0.299, 0.587, 0.114]) # 根据 RGB 值的权重计算灰度值
# 输出结果
print(img_reshape.shape)
print(img_enhanced.shape)
print(img_gray.shape)