import cv2
import numpy as np
# This is just a simple helper function that takes a matrix, converts it to
# the BGR colorspace (if necessary), shows it with .imshow() and waits using
# .waitKey() feel free to ignore it.
def show(*, img_bgr=None, img_rgb=None):
if img_bgr is None:
img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
cv2.imshow("title", img_bgr)
cv2.waitKey()
transform = np.array([
[ 0.06, 0.63 , 0.27],
[ 0.3 , 0.04 , -0.35],
[ 0.34, -0.6 , 0.17]
])
img_bgr = cv2.imread("lenna.png",)
# The image will be in BGR order, we want RGB order
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
# This does three things:
# - Transforms the pixels according to the transform matrix
# - Rounds the pixel values to integers
# - Coverts the datatype of the matrix to 'uint8' show .imshow() works
img_trans = np.rint(img_rgb.dot(transform.T)).astype('uint8')
show(img_bgr=img_bgr)
show(img_rgb=img_trans)
你可以这样做:
其中,来自:
产生:
注意:如果您正在寻找以下内容:
然后删除转置(
...dot(transform.T)...
->;...dot(transform)...
)相关问题 更多 >
编程相关推荐