First let's try your original algorithm:

import skimage.io
import cv2
img = skimage.io.imread('sample.png')
cv2.imwrite('sample_out_1.png', img)

As you can see, red and blue channels are visibly swapped.
The first approach, assuming you want to still use skimage to read and cv2 to write is to use cv2.cvtColor to convert from RGB to BGR.
Since the new OpenCV docs don't mention Python syntax, in this case you can also use the appropriate reference for 2.4.x.
import skimage.io
import cv2
img = skimage.io.imread('sample.png')
cv2.imwrite('sample_out_2.png', cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
Now we get the following output:

本文介绍了一种使用Python解决图像处理中红蓝通道错位的问题。通过skimage读取图像并利用OpenCV的cv2.cvtColor函数从RGB转换到BGR格式来修正图像颜色通道,最终实现了正确的图像输出。
5770

被折叠的 条评论
为什么被折叠?



