FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
visioncpp/include/operators/convert/OP_RGBToHSV.hpp at master · codeplaysoftware/visioncpp · GitHub
This repository was archived by the owner on Apr 29, 2024. It is now read-only.
codeplaysoftware
visioncpp
Repository navigation
Code
Issues
Pull requests
1
(1)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
visioncpp
/
include
/
operators
/
convert
/
OP_RGBToHSV.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
89 lines (86 loc) · 2.85 KB
Breadcrumbs
visioncpp
/
include
/
operators
/
convert
/
OP_RGBToHSV.hpp
Copy path
File metadata and controls
89 lines (86 loc) · 2.85 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
83
84
85
86
87
88
89
//
This file is part of VisionCpp, a lightweight C++ template library
//
for computer vision and image processing.
//
//
Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
//
//
Contact: visioncpp@codeplay.com
//
//
Licensed under the Apache License, Version 2.0 (the "License");
//
you may not use this file except in compliance with the License.
//
You may obtain a copy of the License at
//
//
http://www.apache.org/licenses/LICENSE-2.0
//
//
Unless required by applicable law or agreed to in writing, software
//
distributed under the License is distributed on an "AS IS" BASIS,
//
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
See the License for the specific language governing permissions and
//
limitations under the License.
//
/ \file OP_RGBToHSV.hpp
//
/ \brief it converts RGB pixel to HSV pixel
namespace
visioncpp
{
//
/ \brief Functor converts RGB ( R: 0.0f..1.0f, G: 0.0f..1.0f, B: 0.0f..1.0f)
//
/ to HSV ( H: 0.0f..360.f, S: 0.0f..1.0f V: 0.0f..1.0f ) color space
struct
OP_RGBToHSV
{
//
/ \param inRGB
//
/ \return F32C3
visioncpp::pixel::
F32C3
operator
()(visioncpp::pixel::
F32C3
inRGB) {
//
Convert from RGB to HSV, using float ranges 0.0 to 1.0.
float
fR
= inRGB[
0
],
fG
= inRGB[
1
],
fB
= inRGB[
2
];
float
fH
=
0
.
0f
,
fS
=
0
.
0f
,
fV
=
0
.
0f
;
float
fDelta
;
float
fMin
,
fMax
;
//
Get the min and max, but use integer comparisons for slight speedup.
if
(inRGB[
2
] < inRGB[
1
]) {
if
(inRGB[
2
] < inRGB[
0
]) {
fMin
=
fB
;
if
(inRGB[
0
] > inRGB[
1
]) {
fMax
=
fR
;
}
else
{
fMax
=
fG
;
}
}
else
{
fMin
=
fR
;
fMax
=
fG
;
}
}
else
{
if
(inRGB[
1
] < inRGB[
0
]) {
fMin
=
fG
;
if
(inRGB[
2
] > inRGB[
0
]) {
fMax
=
fB
;
}
else
{
fMax
=
fR
;
}
}
else
{
fMin
=
fR
;
fMax
=
fB
;
}
}
fDelta
=
fMax
-
fMin
;
fV
=
fMax
;
//
Value (Brightness).
if
(
fMax
!=
0
.
0f
) {
//
Make sure it's not pure black.
fS
=
fDelta
/
fMax
;
//
Saturation.
float
ANGLE_TO_UNIT
=
1
.
0f
/
(
6
.
0f
*
fDelta
);
//
Make the Hues between 0.0 to 1.0 instead of 6.0
if
(
fDelta
==
0
.
0f
) {
fH
=
0
.
0f
;
//
undefined hue
}
else
if
(
fMax
== inRGB[
0
]) {
//
between yellow and magenta.
fH
= (
fG
-
fB
) *
ANGLE_TO_UNIT
;
}
else
if
(
fMax
== inRGB[
1
]) {
//
between cyan and yellow.
fH
= (
2
.
0f
/
6
.
0f
) + (
fB
-
fR
) *
ANGLE_TO_UNIT
;
}
else
{
//
between magenta and cyan.
fH
= (
4
.
0f
/
6
.
0f
) + (
fR
-
fG
) *
ANGLE_TO_UNIT
;
}
//
Wrap outlier Hues around the circle.
if
(
fH
<
0
.
0f
)
fH
+=
1
.
0f
;
if
(
fH
>=
1
.
0f
)
fH
-=
1
.
0f
;
}
else
{
//
color is pure Black.
fS
=
0
.
0f
;
fH
=
0
.
0f
;
//
undefined hue
}
return
visioncpp::pixel::F32C3
(
fH
,
fS
,
fV
);
}
};
}
Back
|
FazBrowse Home
|
New Git URL