前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Color model 色彩模型

Color model 色彩模型

原创
作者头像
vanguard
修改2020-03-10 10:59:01
1.4K0
修改2020-03-10 10:59:01
举报
文章被收录于专栏:vanguard

A color model is a system for creating a full range of colours from a small set of primary colors. There are two types of colour models: additive and subtractive. Additive color modelsuse light to display color, while subtractive color models use printing inks.

颜色模型指的是某个三维颜色空间中的一个可见光子集,它包含某个色彩域的所有色彩。一般而言,任何一个色彩域都只是可见光的子集,任何一个颜色模型都无法包含所有的可见光。常见的颜色模型有RGB CIECMY/CMYK、(HSK NTSC、YcbCr、HSV 等。

BGR/RGB <-> HLS/HSV <-> GRAY <-> BINARY

BGR (blue, green, red) and RGB (red, green, blue) w*h*3*[0-255]

HSL (hue, saturation, lightness) and HSV (hue, saturation, value) w*h*3

Gray = w*h*[0-255] Binary = w*h*[0/1]

代码语言:python
代码运行次数:0
复制
# RGB/BGR <-> HSL/HSV/GRAY
cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.cvtColor(image, cv2.COLOR_BGR2HSL)
# white color mask
lower = np.uint8([123, 116, 116])
upper = np.uint8([186, 172, 160])
white_mask = cv2.inRange(image, lower, upper)
# yellow color mask
lower = np.uint8([134, 121, 100])
upper = np.uint8([206, 155, 87])
yellow_mask = cv2.inRange(image, lower, upper)

# Gray -> Binary
cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) # min 127, max 255
cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
cv2.threshold(gray, 127, 255, cv2.THRESH_TRUNC)
cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO_INV)

# Binary -> Gray -> BGR
np.array(binary*255).astype(np.uint8)
cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)

# HSV/HSL color filter
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# white color mask
lower = np.uint8([0, 0, 0])
upper = np.uint8([0, 0, 255])
white_mask = cv2.inRange(hsv, lower, upper)
# yellow color mask
lower = np.uint8([ 10,   0, 100])
upper = np.uint8([ 40, 255, 255])
yellow_mask = cv2.inRange(hsv, lower, upper)
# combine the mask
mask = cv2.bitwise_or(white_mask, yellow_mask)

# combine the mask
mask = cv2.bitwise_or(white_mask, yellow_mask)
target = cv2.bitwise_and(img,img, mask=mask)

# ch_binary = np.zeros_like(img[:,:,int(ch-1)])
# ch_binary[(img[:,:,int(ch-1)]>=ch_thresh[0])&(img[:,:,int(ch-1)]<=ch_thresh[1])] = 1

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档