先说结论
 skimage.io.imread读取的通道顺序为RGB,
 opencv读取的通道顺序为BGR。
 在基于通道处理数据时注意区别。
示例如下:
 对于一张彩色的村庄鸟瞰图,
 其中道路为蓝色,我们提取出蓝色通道
 并将其转为二值图输出,已验证提取出的通道为蓝色通道
 
代码实现:
cv2 读取
import cv2 as cv
img_path = 'path_to_image'
image=cv.imread(img_path)  # 
blue_channel = image[:, :, 0]
# 设置下界阈值
lower_threshold = 50
# 创建二值化图像,将满足阈值条件的像素设为1,其他像素设为0
binary_image = np.where((blue_channel <= lower_threshold), 0, 1)
cv.imwrite('testCV2.png', binary_image*255)
输出图像为:
 
skimage读取
from skimage.io import imread
img_path = 'path_to_image'
image=imread(img_path)  # RGB
blue_channel = image[:, :, 2]  
# 设置下界阈值
lower_threshold = 50
# 创建二值化图像,将满足阈值条件的像素设为1,其他像素设为0
binary_image = np.where((blue_channel <= lower_threshold), 0, 1)
cv.imwrite('testskimg.png', binary_image*255)
输出结果为:
 



















