FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PMRID/utils.py at training_patch · AlgorithmicIntelligence/PMRID · GitHub
AlgorithmicIntelligence
/
PMRID
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PMRID
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (62 loc) · 1.96 KB
Breadcrumbs
PMRID
/
utils.py
Copy path
File metadata and controls
75 lines (62 loc) · 1.96 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
#!/usr/bin/env python3
import
cv2
import
numpy
as
np
class
RawUtils
:
@
classmethod
def
bggr2rggb
(
cls
,
*
bayers
):
res
=
[]
for
bayer
in
bayers
:
res
.
append
(
bayer
[::
-
1
, ::
-
1
])
if
len
(
res
)
==
1
:
return
res
[
0
]
return
res
@
classmethod
def
rggb2bggr
(
cls
,
*
bayers
):
return
cls
.
bggr2rggb
(
*
bayers
)
@
classmethod
def
bayer2rggb
(
cls
,
*
bayers
):
res
=
[]
for
bayer
in
bayers
:
H
,
W
=
bayer
.
shape
res
.
append
(
bayer
.
reshape
(
H
//
2
,
2
,
W
//
2
,
2
)
.
transpose
(
0
,
2
,
1
,
3
)
.
reshape
(
H
//
2
,
W
//
2
,
4
)
)
if
len
(
res
)
==
1
:
return
res
[
0
]
return
res
@
classmethod
def
rggb2bayer
(
cls
,
*
rggbs
):
res
=
[]
for
rggb
in
rggbs
:
H
,
W
,
_
=
rggb
.
shape
res
.
append
(
rggb
.
reshape
(
H
,
W
,
2
,
2
)
.
transpose
(
0
,
2
,
1
,
3
)
.
reshape
(
H
*
2
,
W
*
2
)
)
if
len
(
res
)
==
1
:
return
res
[
0
]
return
res
@
classmethod
def
bayer2rgb
(
cls
,
*
bayer_01s
,
wb_gain
,
CCM
,
gamma
=
2.2
):
wb_gain
=
np
.
array
(
wb_gain
)[[
0
,
1
,
1
,
2
]]
res
=
[]
for
bayer_01
in
bayer_01s
:
bayer_01
=
bayer_01
.
transpose
(
1
,
2
,
0
)
bayer
=
cls
.
rggb2bayer
(
(
bayer_01
*
wb_gain
).
clip
(
0
,
1
)
).
astype
(
np
.
float32
)
# bayer = cls.rggb2bayer(
# (cls.bayer2rggb(bayer_01) * wb_gain).clip(0, 1)
# ).astype(np.float32)
bayer
=
np
.
round
(
np
.
ascontiguousarray
(
bayer
)
*
65535
).
clip
(
0
,
65535
).
astype
(
np
.
uint16
)
rgb
=
cv2
.
cvtColor
(
bayer
,
cv2
.
COLOR_BAYER_BG2RGB_EA
).
astype
(
np
.
float32
)
/
65535
rgb
=
rgb
.
dot
(
np
.
array
(
CCM
).
T
).
clip
(
0
,
1
)
rgb
=
rgb
**
(
1
/
gamma
)
res
.
append
(
rgb
.
astype
(
np
.
float32
))
if
len
(
res
)
==
1
:
return
res
[
0
]
return
res
# vim: ts=4 sw=4 sts=4 expandtab
Back
|
FazBrowse Home
|
New Git URL