Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
OpenCVWithPythonByExample/ImageColorSpace.html at gh-pages · ilikeyml/OpenCVWithPythonByExample · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ilikeyml
OpenCVWithPythonByExample
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
gh-pages
Breadcrumbs
OpenCVWithPythonByExample
/
ImageColorSpace.html
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
82 lines (76 loc) · 4.38 KB
gh-pages
Breadcrumbs
OpenCVWithPythonByExample
/
ImageColorSpace.html
Copy path
Top
File metadata and controls
Code
Blame
82 lines (76 loc) · 4.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html
>
<
html
>
<
head
>
<
meta
charset
='
utf-8
'
>
<
meta
http-equiv
="
X-UA-Compatible
"
content
="
chrome=1
"
>
<
meta
name
="
description
"
content
="
Opencvwithpythonbyexample : Simple demos using OpenCV for Python
"
>
<
link
rel
="
stylesheet
"
type
="
text/css
"
media
="
screen
"
href
="
stylesheets/stylesheet.css
"
>
<
title
>
OpenCV With Python By Example
</
title
>
</
head
>
<
body
>
<!-- HEADER -->
<
div
id
="
header_wrap
"
class
="
outer
"
>
<
header
class
="
inner
"
>
<
a
id
="
forkme_banner
"
href
="
https://github.com/ilikeyml/OpenCVWithPythonByExample
"
>
View on GitHub
</
a
>
<
a
href
="
http://ilikeyml.github.io/OpenCVWithPythonByExample/
"
>
<
h1
id
="
project_title
"
>
OpenCV With Python By Example
</
h1
>
</
a
>
<
h2
id
="
project_tagline
"
>
Simple demos using OpenCV for Python
</
h2
>
</
header
>
</
div
>
<!-- MAIN CONTENT -->
<
div
id
="
main_content_wrap
"
class
="
outer
"
>
<
section
id
="
main_content
"
class
="
inner
"
>
<
h2
>
图像色彩空间
</
h2
>
<
h3
>
1.RGB
</
h3
>
<
p
>
RGB是最常用的色彩空间,将一副图像表示为R、G、B三个通道分量合成后的结果
</
p
>
<
h3
>
2.YUV
</
h3
>
<
p
>
YUV将图像分为亮度Y以及色差U、V三个信号。其中“Y”表示明亮度(Luminance或Luma),也就是灰阶值;而“U”和“V” 表示的则是色度(Chrominance或Chroma),作用是描述影像色彩及饱和度,用于指定像素的颜色。“亮度”是透过RGB输入信号来建立的,方法是将RGB信号的特定部分叠加到一起。“色度”则定义了颜色的两个方面─色调与饱和度,分别用Cr和Cb来表示。其中,Cr反映了RGB输入信号红色部分与RGB信号亮度值之间的差异。而Cb反映的是RGB输入信号蓝色部分与RGB信号亮度值之间的差异。
</
p
>
<
h3
>
3.HSV
</
h3
>
<
p
>
HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model)。
<
br
>
这个模型中颜色的参数分别是:色调(H),饱和度(S),亮度(V)。
<
br
>
<
strong
>
色调H
</
strong
>
<
br
>
用角度度量,取值范围为0°~360°,从红色开始按逆时针方向计算,红色为0°,绿色为120°,蓝色为240°。它们的补色是:黄色为60°,青色为180°,品红为300°。
<
br
>
<
strong
>
饱和度S
</
strong
>
<
br
>
取值范围为0.0~1.0,值越大,颜色越饱和。
<
br
>
<
strong
>
亮度V
</
strong
>
<
br
>
亮度V通常用百分比度量,从0%(黑)到100%(白)。
RGB和CMY颜色模型都是面向硬件的,而HSV(Hue Saturation Value)颜色模型是面向用户的。
HSV模型的三维表示从RGB立方体演化而来。设想从RGB沿立方体对角线的白色顶点向黑色顶点观察,就可以看到立方体的六边形外形。六边形边界表示色彩,水平轴表示纯度,明度沿垂直轴测量。
<
img
src
="
accessories/HSV.jpg
"
alt
="
Color Space
"
>
</
p
>
<
p
>
<
strong
>
三个图像空间可以通过OpenCV自带的函数进行转换
</
strong
>
<
br
>
数字图像处理中通常会对彩色图像进行分通道处理
</
p
>
<
p
>
1.读取一副图像
<
br
>
<
code
>
import cv2 as cv
</
code
>
<
br
>
<
code
>
img = cv.imread("../ImageSource/redSample.jpg")
</
code
>
<
br
>
<
code
>
cv.imshow("in", img)
</
code
>
<
br
>
<
code
>
print img.shape
</
code
>
<
br
>
调用
<
em
>
print img.shape
</
em
>
我们可以得到
<
em
>
img
</
em
>
的数据结构
<
br
>
<
code
>
(196, 279, 3)
</
code
>
<
br
>
最后一位“3”表示
<
em
>
img
</
em
>
的三个通道
<
br
>
OpenCV默认的通道顺序为B-G-R
<
br
>
<
code
>
B, G, R = cv.split(img)
</
code
>
<
br
>
<
code
>
cv.imshow("B channel", B)
</
code
>
<
br
>
<
code
>
cv.imshow("G channel", G)
</
code
>
<
br
>
<
code
>
cv.imshow("R channel", R)
</
code
>
<
br
>
<
img
src
="
accessories/BGRSplit.png
"
alt
="
BGRSplit
"
>
<
br
>
<
strong
>
色彩空间转换
</
strong
>
</
p
>
<
p
>
<
code
>
#BGR2YUV 转换
</
code
>
<
br
>
<
code
>
img_YUVtrans = cv.cvtColor(img,cv.COLOR_BGR2YUV)
</
code
>
<
br
>
<
code
>
cv.imshow("YUV mode", img_YUVtrans)
</
code
>
<
br
>
<
code
>
#BGR2HSV 转换
</
code
>
<
br
>
<
code
>
img_HSVtrans = cv.cvtColor(img, cv.COLOR_BGR2HSV)
</
code
>
<
br
>
<
code
>
cv.imshow("HSV mode", img_HSVtrans)
</
code
>
<
br
>
<
img
src
="
accessories/colorSpace.png
"
alt
="
ColorSpace
"
>
</
p
>
</
section
>
</
div
>
<!-- FOOTER -->
<
div
id
="
footer_wrap
"
class
="
outer
"
>
<
footer
class
="
inner
"
>
<
p
class
="
copyright
"
>
OpenCV with Python by Example maintained by
<
a
href
="
https://github.com/ilikeyml
"
>
ilikeyml
</
a
>
</
p
>
<
p
>
Published with
<
a
href
="
https://pages.github.com
"
>
GitHub Pages
</
a
>
</
p
>
</
footer
>
</
div
>
</
body
>
</
html
>
You can’t perform that action at this time.