您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将转换矩阵应用于OpenCV图像中的像素

将转换矩阵应用于OpenCV图像中的像素

记不清执行此操作的规范方法(可能避免了转置),但这应该可行:

import numpy as np

M = np.random.random_sample((3, 3))

rgb = np.random.random_sample((5, 4, 3))

slow_result = np.zeros_like(rgb)
for i in range(rgb.shape[0]):
    for j in range(rgb.shape[1]):
        slow_result[i, j, :] = np.dot(M, rgb[i, j, :])

# faster method
rgb_reshaped = rgb.reshape((rgb.shape[0] * rgb.shape[1], rgb.shape[2]))
result = np.dot(M, rgb_reshaped.T).T.reshape(rgb.shape)

print np.allclose(slow_result, result)

如果是标准色彩空间之间的转换,则应使用Scikit Image:

其他 2022/1/1 18:28:06 有461人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶