提取图像的各个通道,进行显示
程序员文章站
2022-04-01 09:44:23
...
# -*- coding: utf-8 -*-
"""
Created on Tue May 8 19:11:52 2018
@author: PC
"""
import cv2
import numpy as np
img = cv2.imread('C:/Users/PC/Desktop/program/skin/Images/self2.jpg') #低反光
cv2.imshow('image',img)
## =============================================================================
## 去除光照不均
## =============================================================================
#img_HSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #提取V通道
#H, S, V = cv2.split(img_HSV)
#B, G, R = cv2.split(img)
#
#kernel = np.ones((11,11),np.float32)/121
#mask = cv2.filter2D(V,-1,kernel) # V通道均值
#mask1 = (mask/256) * (mask/256) * 256 # 建立函数,使低值像素分布更细腻,抛物线函数
#mask2 = mask1.astype(np.uint8)
#V1 = cv2.normalize(mask2, None, 0, 125, cv2.NORM_MINMAX) #归一化,数值分布到 range(0,100)
## cv2.imshow('mask1',V1)
#B = cv2.subtract(B, V1)
#G = cv2.subtract(G, V1)
#R = cv2.subtract(R, V1)
#dst = cv2.merge((B,G,R))
#img = cv2.normalize(dst, None, 0, 255, cv2.NORM_MINMAX)
#cv2.imshow("light", img)
#cv2.imwrite("C:/Users/PC/Desktop/test.jpg", dst)
B, G, R = cv2.split(img)
cv2.imshow("B", B)
cv2.imshow("G", G)
cv2.imshow("R", R)
#B = np.zeros(R.shape[:2])
#G = np.zeros(R.shape[:2])
#
#img1 = cv2.merge([B.astype(np.uint8), G.astype(np.uint8), R.astype(np.uint8)])
#cv2.imshow('image1',img1)
HLS_img = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
HLS_H, HLS_L, HLS_S = cv2.split(HLS_img)
cv2.imshow("HLS_H", HLS_H)
cv2.imshow("HLS_L", HLS_L)
cv2.imshow("HLS_S", HLS_S)
HSV_img = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
HSV_H, HSV_S, HSV_V = cv2.split(HSV_img)
cv2.imshow("HSV_H", HSV_H)
cv2.imshow("HSV_S", HSV_S)
cv2.imshow("HSV_V", HSV_V)
YCrCb_img = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
YCrCb_Y, YCrCb_Cr, YCrCb_Cb = cv2.split(YCrCb_img)
cv2.imshow("YCrCb_Y", YCrCb_Y)
cv2.imshow("YCrCb_Cr", YCrCb_Cr)
cv2.imshow("YCrCb_Cb", YCrCb_Cb)
YUV_img = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
YUV_Y, YUV_U, YUV_V = cv2.split(YUV_img)
cv2.imshow("YUV_Y", YUV_Y)
cv2.imshow("YUV_U", YUV_U)
cv2.imshow("YUV_V", YUV_V)
cv2.waitKey(0)
cv2.destroyAllWindows()