Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BachelorDeeplearning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s184400
BachelorDeeplearning
Commits
48d55efe
Commit
48d55efe
authored
4 years ago
by
Gustav Als
Browse files
Options
Downloads
Patches
Plain Diff
smarter way of handling overflow
parent
e8a1afb9
Branches
Branches containing commit
No related tags found
1 merge request
!2
Prepocessing
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
color_constancy.py
+8
-17
8 additions, 17 deletions
color_constancy.py
with
8 additions
and
17 deletions
color_constancy.py
+
8
−
17
View file @
48d55efe
...
...
@@ -171,7 +171,7 @@ def general_color_constancy(image, gaussian_differentiation=0, minkowski_norm=5,
mask_image2
=
set_border
(
mask_image2
,
sigma
+
1
)
out_image
=
np
.
ndarray
.
copy
(
image
)
out_image
=
np
.
ndarray
.
copy
(
image
)
.
astype
(
int
)
if
gaussian_differentiation
==
0
:
if
sigma
!=
0
:
...
...
@@ -211,21 +211,12 @@ def general_color_constancy(image, gaussian_differentiation=0, minkowski_norm=5,
white_G
=
white_G
/
som
white_B
=
white_B
/
som
white_R_coef
=
white_R
*
np
.
sqrt
(
3.0
)
white_G_coef
=
white_G
*
np
.
sqrt
(
3.0
)
white_B_coef
=
white_B
*
np
.
sqrt
(
3.0
)
out_image
[:,
:,
0
]
=
out_image
[:,
:,
0
]
/
(
white_R
*
np
.
sqrt
(
3.0
)
)
out_image
[:,
:,
1
]
=
out_image
[:,
:,
1
]
/
(
white_G
*
np
.
sqrt
(
3.0
)
)
out_image
[:,
:,
2
]
=
out_image
[:,
:,
2
]
/
(
white_B
*
np
.
sqrt
(
3.0
)
)
#Handles problem with overflowing pixel values when the coefficients are below 1
if
white_R_coef
<=
1.0
:
white_R_coef
=
1
if
white_G_coef
<=
1.0
:
white_G_coef
=
1
if
white_B_coef
<=
1.0
:
white_B_coef
=
1
out_image
[:,
:,
0
]
=
out_image
[:,
:,
0
]
/
white_R_coef
out_image
[:,
:,
1
]
=
out_image
[:,
:,
1
]
/
white_G_coef
out_image
[:,
:,
2
]
=
out_image
[:,
:,
2
]
/
white_B_coef
#Makes sure there is no overflow
out_image
[
out_image
>=
255
]
=
255
return
white_R
,
white_G
,
white_B
,
out_image
...
...
@@ -234,7 +225,7 @@ test_img = cv2.imread(r'C:\Users\Bruger\Pictures\building1.jpg', 1)
im_rgb
=
cv2
.
cvtColor
(
test_img
,
cv2
.
COLOR_BGR2RGB
)
R
,
G
,
B
,
test_img1
=
general_color_constancy
(
im_rgb
,
gaussian_differentiation
=
1
,
minkowski_norm
=
5
,
sigma
=
1
)
R
,
G
,
B
,
test_img1
=
general_color_constancy
(
im_rgb
,
gaussian_differentiation
=
0
,
minkowski_norm
=
6
,
sigma
=
0
)
fig
=
plt
.
figure
(
figsize
=
(
9
,
12
))
...
...
@@ -242,7 +233,7 @@ fig.add_subplot(1,2,1)
plt
.
imshow
(
im_rgb
)
fig
.
add_subplot
(
1
,
2
,
2
)
plt
.
imshow
(
test_img1
.
astype
(
'
uint8
'
)
)
plt
.
imshow
(
test_img1
)
plt
.
show
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment