擅长:python、mysql、java
<p>请注意,此操作将矩阵(图像)的<code>dtype</code>从<code>uint8</code>更改为{<cd3>},这可能导致其他{a1}。IMO,一个更好(更有效)的方法是:</p>
<pre><code>import cv2
import numpy as np
img = cv2.imread('image.png').astype(np.float) # BGR, float
img[:, :, 2] = np.absolute(img[:, :, 2] - img[:, :, 0]) # R = |R - B|
img = img.astype(np.uint8) # convert back to uint8
cv2.imwrite('new-image.png', img) # save the image
cv2.imshow('img', img)
cv2.waitKey()
</code></pre>